Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Box<_> support for serde #45

Closed
Byron opened this issue Mar 20, 2015 · 2 comments
Closed

Box<_> support for serde #45

Byron opened this issue Mar 20, 2015 · 2 comments

Comments

@Byron
Copy link
Contributor

Byron commented Mar 20, 2015

I have a recursive structure which looks very much like this:

/// There is no detailed description.
/// 
/// This type is not used in any activity, and only used as *part* of another schema.
/// 
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct ItemScope {
    /// The start date and time of the event (in ISO 8601 date format).    
    #[serde(alias="startDate")]
    pub start_date: String,
    /// The end date and time of the event (in ISO 8601 date format).    
    #[serde(alias="endDate")]
    pub end_date: String,
    /// The text that is the result of the app activity. For example, if a user leaves a review of a restaurant, this might be the text of the review.    
    pub text: String,
    /// A URL to the image that represents this result. For example, if a user writes a review of a restaurant and attaches a photo of their meal, you might use that photo as the result.image.    
    pub image: String,
    /// Review rating.    
    #[serde(alias="reviewRating")]
    pub review_rating: Option<Box<ItemScope>>,
}

As you can see, I have to use a Box to allow such a struct to exist. With rustc_serialize, I was able to encode and decode it, with serde I get errors like this:

the trait `serde::de::Deserialize` is not implemented for the type `Box<ItemScope>`

This is just happening for me in the plus1 API, so it's by no means a show-stopper.
Also I may note that with an older compiler version (and rustc_serialize) I was able to just use Box<ItemScope> without issues. Now, it really wants Option<Box<ItemScope>> - may be a bug.

Details on where this issue is coming from can be watched on youtube.

Meta

✗ rustc --version --verbose
rustc 1.0.0-nightly (ea8b82e90 2015-03-17) (built 2015-03-18)
binary: rustc
commit-hash: ea8b82e90c450febb1f26a07862a1ec89c22addd
commit-date: 2015-03-17
build-date: 2015-03-18
host: x86_64-apple-darwin
release: 1.0.0-nightly
➜  rust-serde git:(master) glog
* 42bd905 (HEAD, mine/master, master) fix(macros): fully qualified usage of `Result`
* 5378d22 (origin/master, origin/HEAD) Switch to the new custom_deserialize syntax
* c8b2ad0 Update to rust HEAD
* e778c7e Update to rust HEAD
*   f0d0dd2 Merge pull request #41 from hugoduncan/feature/mark-field-attributes-used
|\
| * 3e63d34 Mark serde field attributes as used
|/
Byron added a commit to Byron/google-apis-rs that referenced this issue Mar 21, 2015
They currently don't compile as Box 'serde' is not supported.
See serde-rs/serde#45.

Related to #34.
@tomprogrammer
Copy link
Contributor

Is this fixed by #49?

@Byron
Copy link
Contributor Author

Byron commented Apr 7, 2015

Yes, this works for me now, thank you !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants