{"action":"created","issue":{"url":"https://api.github.com/repos/serde-rs/serde/issues/386","repository_url":"https://api.github.com/repos/serde-rs/serde","labels_url":"https://api.github.com/repos/serde-rs/serde/issues/386/labels{/name}","comments_url":"https://api.github.com/repos/serde-rs/serde/issues/386/comments","events_url":"https://api.github.com/repos/serde-rs/serde/issues/386/events","html_url":"https://github.com/serde-rs/serde/issues/386","id":160347123,"number":386,"title":"Unable to serialize sequence without knowing all elements.","user":{"login":"dpc","id":9209,"avatar_url":"https://avatars.githubusercontent.com/u/9209?v=3","gravatar_id":"","url":"https://api.github.com/users/dpc","html_url":"https://github.com/dpc","followers_url":"https://api.github.com/users/dpc/followers","following_url":"https://api.github.com/users/dpc/following{/other_user}","gists_url":"https://api.github.com/users/dpc/gists{/gist_id}","starred_url":"https://api.github.com/users/dpc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dpc/subscriptions","organizations_url":"https://api.github.com/users/dpc/orgs","repos_url":"https://api.github.com/users/dpc/repos","events_url":"https://api.github.com/users/dpc/events{/privacy}","received_events_url":"https://api.github.com/users/dpc/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/serde-rs/serde/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-06-15T06:25:16Z","updated_at":"2016-07-10T04:24:54Z","closed_at":null,"body":"In the logging library I'm working on, I would like to serialize map elements, provided by user API calls. However at any given time, I have only one `key: value` pair.\r\n\r\nSo I can't efficiently serialize a map:\r\n\r\n```\r\n    fn serialize_map<V>(&mut self, visitor: V) -> Result<(), Self::Error> where V: MapVisitor;\r\n    fn serialize_map_elt<K, V>(&mut self, key: K, value: V) -> Result<(), Self::Error> where K: Serialize, V: Serialize;\r\n```\r\n\r\nAs I have to build a Visitor\r\n\r\nIf the API would be returning some kind of `Visitor` that one can call to serialize field after field, then both my and currently-supported use cases would work. Would it be worse in some aspect that I'm missing?"},"comment":{"url":"https://api.github.com/repos/serde-rs/serde/issues/comments/231569986","html_url":"https://github.com/serde-rs/serde/issues/386#issuecomment-231569986","issue_url":"https://api.github.com/repos/serde-rs/serde/issues/386","id":231569986,"user":{"login":"dpc","id":9209,"avatar_url":"https://avatars.githubusercontent.com/u/9209?v=3","gravatar_id":"","url":"https://api.github.com/users/dpc","html_url":"https://github.com/dpc","followers_url":"https://api.github.com/users/dpc/followers","following_url":"https://api.github.com/users/dpc/following{/other_user}","gists_url":"https://api.github.com/users/dpc/gists{/gist_id}","starred_url":"https://api.github.com/users/dpc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dpc/subscriptions","organizations_url":"https://api.github.com/users/dpc/orgs","repos_url":"https://api.github.com/users/dpc/repos","events_url":"https://api.github.com/users/dpc/events{/privacy}","received_events_url":"https://api.github.com/users/dpc/received_events","type":"User","site_admin":false},"created_at":"2016-07-10T04:24:54Z","updated_at":"2016-07-10T04:24:54Z","body":"I am keep hitting this problem. The more I look at it, the more I'm convinced that that the `Visitor` pattern is backwards (inversion of control). The `Visitor` should be returned by `serialize_map`, and not taken. The whole `Serializer` API is \"push\"-y - meaning you call methods from the outside for each element you have, and suddenly, when you want to serialize map, it becomes \"pull\" - serde is calling into custom struct (`Visitor`) to ask about all elements. It forces you to create weird `struct MyVistior` and implement error-prone logic, play with lifetimes etc."}}
{"actor":{"display_login":"dpc"}}