11use alloc:: borrow:: Cow ;
2+ use alloc:: rc:: Rc ;
23use alloc:: string:: { String , ToString } ;
34use alloc:: vec:: Vec ;
45use serde:: Deserialize ;
@@ -130,23 +131,19 @@ pub struct BucketChecksum<'a> {
130131 #[ serde( default ) ]
131132 pub count : Option < i64 > ,
132133 #[ serde( default ) ]
133- pub subscriptions : BucketSubscriptionReason ,
134+ pub subscriptions : Rc < Vec < BucketSubscriptionReason > > ,
134135 // #[serde(default)]
135136 // #[serde(deserialize_with = "deserialize_optional_string_to_i64")]
136137 // pub last_op_id: Option<i64>,
137138}
138139
139140/// The reason for why a bucket was included in a checkpoint.
140- #[ derive( Debug , Default , Clone ) ]
141+ #[ derive( Debug ) ]
141142pub enum BucketSubscriptionReason {
142- /// A bucket was created for all of the subscription ids we've explicitly requested in the sync
143- /// request.
144- ExplicitlySubscribed { subscriptions : Vec < i64 > } ,
145143 /// A bucket was created from a default stream.
146- IsDefault { stream_name : String } ,
147- /// We're talking to an older sync service not sending the reason.
148- #[ default]
149- Unknown ,
144+ DerivedFromDefaultStream ( String ) ,
145+ /// A bucket was created for a subscription id we've explicitly requested in the sync request.
146+ DerivedFromExplicitSubscription ( i64 ) ,
150147}
151148
152149impl < ' de > Deserialize < ' de > for BucketSubscriptionReason {
@@ -156,37 +153,38 @@ impl<'de> Deserialize<'de> for BucketSubscriptionReason {
156153 {
157154 struct MyVisitor ;
158155
156+ const VARIANTS : & ' static [ & ' static str ] = & [ "def" , "sub" ] ;
157+
159158 impl < ' de > Visitor < ' de > for MyVisitor {
160159 type Value = BucketSubscriptionReason ;
161160
162161 fn expecting ( & self , formatter : & mut core:: fmt:: Formatter ) -> core:: fmt:: Result {
163162 write ! ( formatter, "a subscription reason" )
164163 }
165164
166- fn visit_seq < A > ( self , mut seq : A ) -> Result < Self :: Value , A :: Error >
165+ fn visit_enum < A > ( self , data : A ) -> Result < Self :: Value , A :: Error >
167166 where
168- A : serde:: de:: SeqAccess < ' de > ,
167+ A : serde:: de:: EnumAccess < ' de > ,
169168 {
170- let mut subscriptions = Vec :: < i64 > :: new ( ) ;
171-
172- while let Some ( item) = seq. next_element :: < & ' de str > ( ) ? {
173- subscriptions. push ( item. parse ( ) . map_err ( |_| A :: Error :: custom ( "not an int" ) ) ?) ;
174- }
175-
176- Ok ( BucketSubscriptionReason :: ExplicitlySubscribed { subscriptions } )
177- }
169+ let ( key, variant) = data. variant :: < & ' de str > ( ) ?;
170+ Ok ( match key {
171+ "def" => BucketSubscriptionReason :: DerivedFromDefaultStream (
172+ variant. newtype_variant ( ) ?,
173+ ) ,
174+ "sub" => {
175+ let textual_id = variant. newtype_variant :: < & ' de str > ( ) ?;
176+ let id = textual_id
177+ . parse ( )
178+ . map_err ( |_| A :: Error :: custom ( "not an int" ) ) ?;
178179
179- fn visit_str < E > ( self , v : & str ) -> Result < Self :: Value , E >
180- where
181- E : serde:: de:: Error ,
182- {
183- Ok ( BucketSubscriptionReason :: IsDefault {
184- stream_name : v. to_string ( ) ,
180+ BucketSubscriptionReason :: DerivedFromExplicitSubscription ( id)
181+ }
182+ other => return Err ( A :: Error :: unknown_variant ( other, VARIANTS ) ) ,
185183 } )
186184 }
187185 }
188186
189- deserializer. deserialize_any ( MyVisitor )
187+ deserializer. deserialize_enum ( "BucketSubscriptionReason" , VARIANTS , MyVisitor )
190188 }
191189}
192190
0 commit comments