{"action":"created","issue":{"url":"https://api.github.com/repos/serde-rs/json/issues/412","repository_url":"https://api.github.com/repos/serde-rs/json","labels_url":"https://api.github.com/repos/serde-rs/json/issues/412/labels{/name}","comments_url":"https://api.github.com/repos/serde-rs/json/issues/412/comments","events_url":"https://api.github.com/repos/serde-rs/json/issues/412/events","html_url":"https://github.com/serde-rs/json/issues/412","id":297355415,"number":412,"title":"Is there a way to parse a number from string?","user":{"login":"vityafx","id":1146369,"avatar_url":"https://avatars3.githubusercontent.com/u/1146369?v=4","gravatar_id":"","url":"https://api.github.com/users/vityafx","html_url":"https://github.com/vityafx","followers_url":"https://api.github.com/users/vityafx/followers","following_url":"https://api.github.com/users/vityafx/following{/other_user}","gists_url":"https://api.github.com/users/vityafx/gists{/gist_id}","starred_url":"https://api.github.com/users/vityafx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vityafx/subscriptions","organizations_url":"https://api.github.com/users/vityafx/orgs","repos_url":"https://api.github.com/users/vityafx/repos","events_url":"https://api.github.com/users/vityafx/events{/privacy}","received_events_url":"https://api.github.com/users/vityafx/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-02-15T07:50:00Z","updated_at":"2018-02-15T08:56:37Z","closed_at":null,"author_association":"NONE","body":"Let's say we have an example:\r\n\r\n```json\r\n{\r\n    \"user\": {\r\n        \"id\": \"78358783457112\"\r\n    }\r\n}\r\n```\r\n\r\nIs there a way to parse it into this:\r\n\r\n```rust\r\n#[derive(Deserialize)]\r\nstruct UserId(pub u64)\r\n\r\n#[derive(Deserialize)]\r\nstruct User {\r\n    user_id: UserId\r\n}\r\n```\r\n\r\nAt this moment it works perfectly and does not parse this because of types: the `u64` type is expected rather than `String`. However, I'd like to have an option to parse numbers from string too. What about doing it like this?\r\n\r\n```rust\r\n#[derive(Deserialize)]\r\nstruct User {\r\n    #[serde(from_string)]\r\n    user_id: UserId\r\n}\r\n```\r\n\r\nI was unable to find something like this in the documentation, if there is such an option, feel free to point me right there."},"comment":{"url":"https://api.github.com/repos/serde-rs/json/issues/comments/365862649","html_url":"https://github.com/serde-rs/json/issues/412#issuecomment-365862649","issue_url":"https://api.github.com/repos/serde-rs/json/issues/412","id":365862649,"user":{"login":"vityafx","id":1146369,"avatar_url":"https://avatars3.githubusercontent.com/u/1146369?v=4","gravatar_id":"","url":"https://api.github.com/users/vityafx","html_url":"https://github.com/vityafx","followers_url":"https://api.github.com/users/vityafx/followers","following_url":"https://api.github.com/users/vityafx/following{/other_user}","gists_url":"https://api.github.com/users/vityafx/gists{/gist_id}","starred_url":"https://api.github.com/users/vityafx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vityafx/subscriptions","organizations_url":"https://api.github.com/users/vityafx/orgs","repos_url":"https://api.github.com/users/vityafx/repos","events_url":"https://api.github.com/users/vityafx/events{/privacy}","received_events_url":"https://api.github.com/users/vityafx/received_events","type":"User","site_admin":false},"created_at":"2018-02-15T08:56:37Z","updated_at":"2018-02-15T08:56:37Z","author_association":"NONE","body":"@dtolnay I'd try doing that, just depends on my free time. Now, it seems, I don't have any other choice, because my code really needs to parse string numbers :) So, this library obviously will not be able to use `serde` attributes because they are owned by another crate which the auxiliary library will depend on. Could you suggest me a name for such an attribute? Or, another way, the auxiliary library could just provide a module with implementations which could be used with:\r\n\r\n```rust\r\n#[derive(Deserialize)]\r\nstruct A {\r\n    [serde(with = \"my_auxiliary_library::string_to_int\")]\r\n    value: u64\r\n}\r\n```"}}
{"actor":{"display_login":"vityafx"}}