use crate::prelude::*; use std::marker::PhantomData; #[derive(Default)] struct MyIterator; impl Iterator for MyIterator { type Item = String; fn next(&mut self) -> Option { unimplemented!() } } // The default trait bounds would require T/U to implement JsonSchema, which MyIterator does not. #[derive(JsonSchema, Serialize, Deserialize, Default)] #[schemars(bound = "T::Item: JsonSchema")] pub struct MyContainer where T: Iterator, U: Iterator, { pub associated: T::Item, #[schemars(bound = "U::Item: JsonSchema")] pub associated2: U::Item, pub phantom: PhantomData, #[serde(skip)] pub _skipped: T, } #[test] fn manual_bound_set() { test!(MyContainer) // TODO with better bounds, this assertion would work: // .assert_identical::>>() .assert_snapshot() .assert_allows_ser_roundtrip_default() .assert_allows_ser_roundtrip([MyContainer { associated: "test".to_owned(), associated2: "test".to_owned(), phantom: PhantomData, _skipped: MyIterator, }]) .assert_matches_de_roundtrip(arbitrary_values()); assert_ne!( >::schema_id(), , MyIterator>>::schema_id() ); assert_ne!( >::schema_id(), >>::schema_id() ); } // `T` doesn't need to impl `JsonSchema`, but `U` does #[derive(JsonSchema, Serialize, Deserialize, Default)] pub struct MyContainer2 where T: Iterator, { pub u: Option, pub phantom: PhantomData, #[serde(skip)] pub _skipped: T, } #[test] fn auto_bound() { test!(MyContainer2) .assert_identical::, Box>>() .assert_snapshot() .assert_allows_ser_roundtrip_default() .assert_allows_ser_roundtrip([MyContainer2 { u: Some("test".to_owned()), phantom: PhantomData, _skipped: MyIterator, }]) .assert_matches_de_roundtrip(arbitrary_values()); }