@@ -38,3 +38,197 @@ pub mod __private {
3838 #[ doc( hidden) ]
3939 pub use log;
4040}
41+
42+ #[ cfg_attr(
43+ all( not( target_os = "solana" ) , feature = "frozen-abi" ) ,
44+ frozen_abi(
45+ api_digest = "3ZRPJYbEUp8VCES2v33cV6T3DtqqT1xe6HWjRmNzQy8L" ,
46+ abi_digest = "9nFE49FJPx9gCu1HCZuw6RtFZQtuRc9LWpahg2j93Ugp"
47+ ) ,
48+ derive( AbiExample , StableAbi )
49+ ) ]
50+ #[ derive( serde:: Serialize , serde:: Deserialize ) ]
51+ struct TestStruct {
52+ sample_u8 : u8 ,
53+ sample_u16 : u16 ,
54+ sample_u32 : u32 ,
55+ sample_u64 : u64 ,
56+ sample_u128 : u128 ,
57+ sample_i8 : i8 ,
58+ sample_i16 : i16 ,
59+ sample_i32 : i32 ,
60+ sample_i64 : i64 ,
61+ sample_i128 : i128 ,
62+ sample_f32 : f32 ,
63+ sample_f64 : f64 ,
64+ sample_bool : bool ,
65+ sample_char : char ,
66+ sample_bytes : [ u8 ; 32 ] ,
67+ sample_tuple : ( u8 , u16 , i32 , bool ) ,
68+ }
69+
70+ #[ cfg( all( feature = "frozen-abi" , not( target_os = "solana" ) ) ) ]
71+ impl solana_frozen_abi:: rand:: distr:: Distribution < TestStruct >
72+ for solana_frozen_abi:: rand:: distr:: StandardUniform
73+ {
74+ fn sample < R : solana_frozen_abi:: rand:: Rng + ?Sized > ( & self , rng : & mut R ) -> TestStruct {
75+ TestStruct {
76+ sample_u8 : rng. random ( ) ,
77+ sample_u16 : rng. random ( ) ,
78+ sample_u32 : rng. random ( ) ,
79+ sample_u64 : rng. random ( ) ,
80+ sample_u128 : rng. random ( ) ,
81+ sample_i8 : rng. random ( ) ,
82+ sample_i16 : rng. random ( ) ,
83+ sample_i32 : rng. random ( ) ,
84+ sample_i64 : rng. random ( ) ,
85+ sample_i128 : rng. random ( ) ,
86+ sample_f32 : rng. random ( ) ,
87+ sample_f64 : rng. random ( ) ,
88+ sample_bool : rng. random ( ) ,
89+ sample_char : rng. random ( ) ,
90+ sample_bytes : rng. random ( ) ,
91+ sample_tuple : ( rng. random ( ) , rng. random ( ) , rng. random ( ) , rng. random ( ) ) ,
92+ }
93+ }
94+ }
95+
96+ #[ cfg_attr(
97+ all( not( target_os = "solana" ) , feature = "frozen-abi" ) ,
98+ frozen_abi(
99+ api_digest = "ikrz9ZPK59Wr2Zk5ujBLVP6P7qwgZA5oRWVBoWbMnDT" ,
100+ abi_digest = "8RY4t5qa1PnwuUfEWssUKcyNkFoyvjma5YVNd24eHeSa"
101+ ) ,
102+ derive( AbiExample , StableAbi )
103+ ) ]
104+ #[ derive( serde:: Serialize , serde:: Deserialize ) ]
105+ struct TestStruct2 {
106+ id : u64 ,
107+ name : [ u8 ; 16 ] ,
108+ flags : ( bool , bool , bool ) ,
109+ list : Vec < u32 > ,
110+ matrix : [ [ f32 ; 4 ] ; 4 ] ,
111+ }
112+
113+ #[ cfg( all( feature = "frozen-abi" , not( target_os = "solana" ) ) ) ]
114+ impl solana_frozen_abi:: rand:: distr:: Distribution < TestStruct2 >
115+ for solana_frozen_abi:: rand:: distr:: StandardUniform
116+ {
117+ fn sample < R : solana_frozen_abi:: rand:: Rng + ?Sized > ( & self , rng : & mut R ) -> TestStruct2 {
118+ TestStruct2 {
119+ id : rng. random ( ) ,
120+ name : rng. random ( ) ,
121+ flags : ( rng. random ( ) , rng. random ( ) , rng. random ( ) ) ,
122+ list : ( 0 ..rng. random_range ( 0 ..10 ) )
123+ . map ( |_| rng. random :: < u32 > ( ) )
124+ . collect ( ) ,
125+ matrix : std:: array:: from_fn ( |_| std:: array:: from_fn ( |_| rng. random ( ) ) ) ,
126+ }
127+ }
128+ }
129+
130+ #[ cfg_attr(
131+ all( not( target_os = "solana" ) , feature = "frozen-abi" ) ,
132+ frozen_abi(
133+ api_digest = "AByXDm8Do84trGaMcL3dUt95u7gqbxHTThZJ4FbAdT4z" ,
134+ abi_digest = "4BPojpfLCiXzb8tdMJTfAe5gR6zsi8ejZZGoU8ybghmY"
135+ ) ,
136+ derive( AbiExample , StableAbi , AbiEnumVisitor )
137+ ) ]
138+ #[ derive( serde:: Serialize , serde:: Deserialize ) ]
139+ enum ExampleEnum {
140+ A ( u8 ) ,
141+ B ( i64 , bool ) ,
142+ C { x : f32 , y : f64 } ,
143+ }
144+
145+ #[ cfg( all( feature = "frozen-abi" , not( target_os = "solana" ) ) ) ]
146+ impl solana_frozen_abi:: rand:: distr:: Distribution < ExampleEnum >
147+ for solana_frozen_abi:: rand:: distr:: StandardUniform
148+ {
149+ fn sample < R : solana_frozen_abi:: rand:: Rng + ?Sized > ( & self , rng : & mut R ) -> ExampleEnum {
150+ match rng. random_range ( 0 ..3 ) {
151+ 0 => ExampleEnum :: A ( rng. random ( ) ) ,
152+ 1 => ExampleEnum :: B ( rng. random ( ) , rng. random ( ) ) ,
153+ _ => ExampleEnum :: C {
154+ x : rng. random ( ) ,
155+ y : rng. random ( ) ,
156+ } ,
157+ }
158+ }
159+ }
160+
161+ #[ cfg_attr(
162+ all( not( target_os = "solana" ) , feature = "frozen-abi" ) ,
163+ frozen_abi(
164+ api_digest = "Dcnq6a62GZdN8FiN4hQ316s6guGJfUW9H5NnjkatYgBL" ,
165+ abi_digest = "9nxf1FgoAsEDAgnMadYaTpWvxyhoEHgFogpdSsrj3Bu5"
166+ ) ,
167+ derive( AbiExample , StableAbi )
168+ ) ]
169+ #[ derive( serde:: Serialize , serde:: Deserialize ) ]
170+ struct TestStruct3 {
171+ maybe_enum : Option < ExampleEnum > ,
172+ vector : Vec < i16 > ,
173+ tuple_array : [ ( u32 , bool ) ; 8 ] ,
174+ }
175+
176+ #[ cfg( all( feature = "frozen-abi" , not( target_os = "solana" ) ) ) ]
177+ impl solana_frozen_abi:: rand:: distr:: Distribution < TestStruct3 >
178+ for solana_frozen_abi:: rand:: distr:: StandardUniform
179+ {
180+ fn sample < R : solana_frozen_abi:: rand:: Rng + ?Sized > ( & self , rng : & mut R ) -> TestStruct3 {
181+ let variant: u8 = rng. random_range ( 0 ..3 ) ;
182+ let maybe_enum = match variant {
183+ 0 => Some ( ExampleEnum :: A ( rng. random ( ) ) ) ,
184+ 1 => Some ( ExampleEnum :: B ( rng. random ( ) , rng. random ( ) ) ) ,
185+ 2 => Some ( ExampleEnum :: C {
186+ x : rng. random ( ) ,
187+ y : rng. random ( ) ,
188+ } ) ,
189+ _ => None ,
190+ } ;
191+
192+ TestStruct3 {
193+ maybe_enum,
194+ vector : ( 0 ..rng. random_range ( 0 ..5 ) )
195+ . map ( |_| rng. random :: < i16 > ( ) )
196+ . collect ( ) ,
197+ tuple_array : std:: array:: from_fn ( |_| ( rng. random ( ) , rng. random ( ) ) ) ,
198+ }
199+ }
200+ }
201+
202+ #[ cfg_attr(
203+ all( not( target_os = "solana" ) , feature = "frozen-abi" ) ,
204+ frozen_abi(
205+ api_digest = "3YuH4YnwWG9fQWrfuJSZArHmTqYP5z8wEsNypUupZP2S" ,
206+ abi_digest = "5kT8YRqxwSZsfknXqLDt2DMhMQCifUd91CTtgx2MAkSY"
207+ ) ,
208+ derive( AbiExample , StableAbi )
209+ ) ]
210+ #[ derive( serde:: Serialize , serde:: Deserialize ) ]
211+ struct TestStruct4 {
212+ inner : TestStruct ,
213+ nested : Vec < TestStruct2 > ,
214+ complex : Option < TestStruct3 > ,
215+ }
216+
217+ #[ cfg( all( feature = "frozen-abi" , not( target_os = "solana" ) ) ) ]
218+ impl solana_frozen_abi:: rand:: distr:: Distribution < TestStruct4 >
219+ for solana_frozen_abi:: rand:: distr:: StandardUniform
220+ {
221+ fn sample < R : solana_frozen_abi:: rand:: Rng + ?Sized > ( & self , rng : & mut R ) -> TestStruct4 {
222+ TestStruct4 {
223+ inner : rng. random ( ) ,
224+ nested : ( 0 ..rng. random_range ( 0 ..3 ) )
225+ . map ( |_| rng. random :: < TestStruct2 > ( ) )
226+ . collect ( ) ,
227+ complex : if rng. random ( ) {
228+ Some ( rng. random :: < TestStruct3 > ( ) )
229+ } else {
230+ None
231+ } ,
232+ }
233+ }
234+ }
0 commit comments