We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I have a struct that uses the attribute #[serde(flatten)] to share fields between multiple structs from an API.
#[serde(flatten)]
For example, I have this:
#[derive(Deserialize, Getter)] #[get = "pub"] struct PartialChapterData { id: u64, language: String, } #[derive(Deserialize, Getters) #[get = "pub"] struct UserChapters { user_id: u64, created: u64, // Unix timestamp chapters: Vec<PartialChapterData>, } #[derive(Deserialize, Getters) #[get = "pub"] struct DetailedChapter { #[serde(flatten)] chapter_partial: PartialChapterData, volume: u16, title: String, } fn main() { 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.
Setter
Edit 1: My workaround for now is to manually implement the setters in DetailedChapter like so:
DetailedChapter
// ... #[derive(Deserialize, Getter)] #[get = "pub"] struct PartialChapterData { id: u64, language: String, } #[derive(Deserialize, Getters) #[get = "pub"] struct DetailedChapter { #[serde(flatten)] chapter_partial: PartialChapterData, volume: u16, title: String, } impl DetailedChapter { pub fn id(&self) -> &u64 { &self.chapter_partial.id() } pub fn language(&self) -> &String { &self.chapter_partial.language() } }
The other getters .volume() and .title() are generated from getset without needing to re-implement them.
.volume()
.title()
getset
The text was updated successfully, but these errors were encountered:
No branches or pull requests
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: