You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a struct that uses the attribute #[serde(flatten)] to share fields between multiple structs from an API.
For example, I have this:
#[derive(Deserialize,Getter)]#[get = "pub"]structPartialChapterData{id:u64,language:String,}#[derive(Deserialize,Getters)#[get = "pub"]structUserChapters{user_id:u64,created:u64,// Unix timestampchapters:Vec<PartialChapterData>,}#[derive(Deserialize,Getters)#[get = "pub"]structDetailedChapter{#[serde(flatten)]chapter_partial:PartialChapterData,volume:u16,title:String,}fnmain(){let test_json = r#"{ "id": 1, "language": "English", "volume": 1, "title": "The Chapter Title" }"#;let detailed_chapter:DetailedChapter = serde_json::from_str(test_json)?;println!("Title: {}\nID: {}",
detailed_chapter.title(), // Does not panic
detailed_chapter.id(), // Panics with the error: error[E0599]: no method named `id` found for reference `&my_test_crate::v2::responses::chapter::DetailedChapter` in the current scope);}
Is there a correct method or workaround for this? I haven't tested the Setter trait as I don't have a need for it.
Edit 1:
My workaround for now is to manually implement the setters in DetailedChapter like so:
I have a struct that uses the attribute
#[serde(flatten)]
to share fields between multiple structs from an API.For example, I have this:
Is there a correct method or workaround for this? I haven't tested the
Setter
trait as I don't have a need for it.Edit 1:
My workaround for now is to manually implement the setters in
DetailedChapter
like so:The other getters
.volume()
and.title()
are generated fromgetset
without needing to re-implement them.The text was updated successfully, but these errors were encountered: