@@ -14,14 +14,14 @@ use std::borrow::{Borrow, Cow};
1414use v8:: { Array , Global , HandleScope , Local , Name , Object , Uint8Array , Value } ;
1515
1616/// Deserializes from V8 values.
17- pub ( super ) struct Deserializer < ' a , ' s > {
18- common : DeserializerCommon < ' a , ' s > ,
19- input : Local < ' s , Value > ,
17+ pub ( super ) struct Deserializer < ' this , ' scope > {
18+ common : DeserializerCommon < ' this , ' scope > ,
19+ input : Local < ' scope , Value > ,
2020}
2121
22- impl < ' a , ' s > Deserializer < ' a , ' s > {
22+ impl < ' this , ' scope > Deserializer < ' this , ' scope > {
2323 /// Creates a new deserializer from `input` in `scope`.
24- pub fn new ( scope : & ' a mut HandleScope < ' s > , input : Local < ' _ , Value > , key_cache : & ' a mut KeyCache ) -> Self {
24+ pub fn new ( scope : & ' this mut HandleScope < ' scope > , input : Local < ' _ , Value > , key_cache : & ' this mut KeyCache ) -> Self {
2525 let input = Local :: new ( scope, input) ;
2626 let common = DeserializerCommon { scope, key_cache } ;
2727 Deserializer { input, common }
@@ -30,16 +30,16 @@ impl<'a, 's> Deserializer<'a, 's> {
3030
3131/// Things shared between various [`Deserializer`]s.
3232///
33- /// The lifetime `'s ` is that of the scope of values deserialized.
34- struct DeserializerCommon < ' a , ' s > {
33+ /// The lifetime `'scope ` is that of the scope of values deserialized.
34+ struct DeserializerCommon < ' this , ' scope > {
3535 /// The scope of values to deserialize.
36- scope : & ' a mut HandleScope < ' s > ,
36+ scope : & ' this mut HandleScope < ' scope > ,
3737 /// A cache for frequently used strings.
38- key_cache : & ' a mut KeyCache ,
38+ key_cache : & ' this mut KeyCache ,
3939}
4040
41- impl < ' s > DeserializerCommon < ' _ , ' s > {
42- fn reborrow ( & mut self ) -> DeserializerCommon < ' _ , ' s > {
41+ impl < ' scope > DeserializerCommon < ' _ , ' scope > {
42+ fn reborrow ( & mut self ) -> DeserializerCommon < ' _ , ' scope > {
4343 DeserializerCommon {
4444 scope : self . scope ,
4545 key_cache : self . key_cache ,
@@ -49,8 +49,8 @@ impl<'s> DeserializerCommon<'_, 's> {
4949
5050/// The possible errors that [`Deserializer`] can produce.
5151#[ derive( Debug , From ) ]
52- pub ( super ) enum Error < ' s > {
53- Value ( Local < ' s , Value > ) ,
52+ pub ( super ) enum Error < ' scope > {
53+ Value ( Local < ' scope , Value > ) ,
5454 Exception ( ExceptionThrown ) ,
5555 Custom ( String ) ,
5656}
@@ -77,22 +77,22 @@ pub(super) struct KeyCache {
7777
7878impl KeyCache {
7979 /// Returns the `tag` property name.
80- pub ( super ) fn tag < ' s > ( & mut self , scope : & mut HandleScope < ' s > ) -> Local < ' s , v8:: String > {
80+ pub ( super ) fn tag < ' scope > ( & mut self , scope : & mut HandleScope < ' scope > ) -> Local < ' scope , v8:: String > {
8181 Self :: get_or_create_key ( scope, & mut self . tag , "tag" )
8282 }
8383
8484 /// Returns the `value` property name.
85- pub ( super ) fn value < ' s > ( & mut self , scope : & mut HandleScope < ' s > ) -> Local < ' s , v8:: String > {
85+ pub ( super ) fn value < ' scope > ( & mut self , scope : & mut HandleScope < ' scope > ) -> Local < ' scope , v8:: String > {
8686 Self :: get_or_create_key ( scope, & mut self . value , "value" )
8787 }
8888
8989 /// Returns an interned string corresponding to `string`
9090 /// and memoizes the creation on the v8 side.
91- fn get_or_create_key < ' s > (
92- scope : & mut HandleScope < ' s > ,
91+ fn get_or_create_key < ' scope > (
92+ scope : & mut HandleScope < ' scope > ,
9393 slot : & mut Option < Global < v8:: String > > ,
9494 string : & str ,
95- ) -> Local < ' s , v8:: String > {
95+ ) -> Local < ' scope , v8:: String > {
9696 if let Some ( s) = & * slot {
9797 v8:: Local :: new ( scope, s)
9898 } else {
@@ -104,24 +104,24 @@ impl KeyCache {
104104}
105105
106106// Creates an interned [`v8::String`].
107- pub ( super ) fn v8_interned_string < ' s > ( scope : & mut HandleScope < ' s > , field : & str ) -> Local < ' s , v8:: String > {
107+ pub ( super ) fn v8_interned_string < ' scope > ( scope : & mut HandleScope < ' scope > , field : & str ) -> Local < ' scope , v8:: String > {
108108 // Internalized v8 strings are significantly faster than "normal" v8 strings
109109 // since v8 deduplicates re-used strings minimizing new allocations
110110 // see: https://github.com/v8/v8/blob/14ac92e02cc3db38131a57e75e2392529f405f2f/include/v8.h#L3165-L3171
111111 v8:: String :: new_from_utf8 ( scope, field. as_ref ( ) , v8:: NewStringType :: Internalized ) . unwrap ( )
112112}
113113
114- /// Extracts a reference `&'s T` from an owned V8 [`Local<'s , T>`].
114+ /// Extracts a reference `&'scope T` from an owned V8 [`Local<'scope , T>`].
115115///
116- /// The lifetime `'s ` is that of the [`HandleScope<'s >`].
116+ /// The lifetime `'scope ` is that of the [`HandleScope<'scope >`].
117117/// This ensures that the reference to `T` won't outlive the `HandleScope`.
118- fn deref_local < ' s , T > ( local : Local < ' s , T > ) -> & ' s T {
118+ fn deref_local < ' scope , T > ( local : Local < ' scope , T > ) -> & ' scope T {
119119 let reference = local. borrow ( ) ;
120- // SAFETY: Lifetime extend `'0` to `'s `.
121- // This is safe as the returned reference `&'s T`
122- // will not outlive its `HandleScope<'s , _>`,
123- // as both are tied to the lifetime `'s `.
124- unsafe { core:: mem:: transmute :: < & T , & ' s T > ( reference) }
120+ // SAFETY: Lifetime extend `'0` to `'scope `.
121+ // This is safe as the returned reference `&'scope T`
122+ // will not outlive its `HandleScope<'scope , _>`,
123+ // as both are tied to the lifetime `'scope `.
124+ unsafe { core:: mem:: transmute :: < & T , & ' scope T > ( reference) }
125125}
126126
127127/// Deserializes a primitive via [`FromValue`].
@@ -133,8 +133,8 @@ macro_rules! deserialize_primitive {
133133 } ;
134134}
135135
136- impl < ' de , ' a , ' s : ' de > de:: Deserializer < ' de > for Deserializer < ' a , ' s > {
137- type Error = Error < ' s > ;
136+ impl < ' de , ' this , ' scope : ' de > de:: Deserializer < ' de > for Deserializer < ' this , ' scope > {
137+ type Error = Error < ' scope > ;
138138
139139 // Deserialization of primitive types defers to `FromValue`.
140140 deserialize_primitive ! ( deserialize_bool, bool ) ;
@@ -242,7 +242,7 @@ impl<'de, 'a, 's: 'de> de::Deserializer<'de> for Deserializer<'a, 's> {
242242 fn deserialize_bytes < V : SliceVisitor < ' de , [ u8 ] > > ( self , visitor : V ) -> Result < V :: Output , Self :: Error > {
243243 let arr = cast ! ( self . common. scope, self . input, Uint8Array , "`Uint8Array` for bytes" ) ?;
244244 let storage: & ' static mut [ u8 ] = & mut [ 0 ; v8:: TYPED_ARRAY_MAX_SIZE_IN_HEAP ] ;
245- let bytes: & ' s [ u8 ] = deref_local ( arr) . get_contents ( storage) ;
245+ let bytes: & ' scope [ u8 ] = deref_local ( arr) . get_contents ( storage) ;
246246 visitor. visit_borrowed ( bytes)
247247 }
248248
@@ -258,27 +258,31 @@ impl<'de, 'a, 's: 'de> de::Deserializer<'de> for Deserializer<'a, 's> {
258258
259259/// Provides access to the field names and values in a JS object
260260/// under the assumption that it's a product.
261- struct ProductAccess < ' a , ' s > {
262- common : DeserializerCommon < ' a , ' s > ,
261+ struct ProductAccess < ' this , ' scope > {
262+ common : DeserializerCommon < ' this , ' scope > ,
263263 /// The input object being deserialized.
264- object : Local < ' s , Object > ,
264+ object : Local < ' scope , Object > ,
265265 /// A field's value, to deserialize next in [`NamedProductAccess::get_field_value_seed`].
266- next_value : Option < Local < ' s , Value > > ,
266+ next_value : Option < Local < ' scope , Value > > ,
267267 /// The index in the product to
268268 index : usize ,
269269}
270270
271271/// Normalizes `field` into an interned `v8::String`.
272- pub ( super ) fn intern_field_name < ' s > ( scope : & mut HandleScope < ' s > , field : Option < & str > , index : usize ) -> Local < ' s , Name > {
272+ pub ( super ) fn intern_field_name < ' scope > (
273+ scope : & mut HandleScope < ' scope > ,
274+ field : Option < & str > ,
275+ index : usize ,
276+ ) -> Local < ' scope , Name > {
273277 let field = match field {
274278 Some ( field) => Cow :: Borrowed ( field) ,
275279 None => Cow :: Owned ( format ! ( "{index}" ) ) ,
276280 } ;
277281 v8_interned_string ( scope, & field) . into ( )
278282}
279283
280- impl < ' de , ' s : ' de > de:: NamedProductAccess < ' de > for ProductAccess < ' _ , ' s > {
281- type Error = Error < ' s > ;
284+ impl < ' de , ' scope : ' de > de:: NamedProductAccess < ' de > for ProductAccess < ' _ , ' scope > {
285+ type Error = Error < ' scope > ;
282286
283287 fn get_field_ident < V : de:: FieldNameVisitor < ' de > > ( & mut self , visitor : V ) -> Result < Option < V :: Output > , Self :: Error > {
284288 let scope = & mut * self . common . scope ;
@@ -330,17 +334,17 @@ impl<'de, 's: 'de> de::NamedProductAccess<'de> for ProductAccess<'_, 's> {
330334
331335/// Used in `Deserializer::deserialize_sum` to translate a `tag` property of a JS object
332336/// to a variant and to provide a deserializer for its value/payload.
333- struct SumAccess < ' a , ' s > {
334- common : DeserializerCommon < ' a , ' s > ,
337+ struct SumAccess < ' this , ' scope > {
338+ common : DeserializerCommon < ' this , ' scope > ,
335339 /// The tag of the sum value.
336- tag : Local < ' s , v8:: String > ,
340+ tag : Local < ' scope , v8:: String > ,
337341 /// The value of the sum value.
338- value : Local < ' s , Value > ,
342+ value : Local < ' scope , Value > ,
339343}
340344
341- impl < ' de , ' a , ' s : ' de > de:: SumAccess < ' de > for SumAccess < ' a , ' s > {
342- type Error = Error < ' s > ;
343- type Variant = Deserializer < ' a , ' s > ;
345+ impl < ' de , ' this , ' scope : ' de > de:: SumAccess < ' de > for SumAccess < ' this , ' scope > {
346+ type Error = Error < ' scope > ;
347+ type Variant = Deserializer < ' this , ' scope > ;
344348
345349 fn variant < V : de:: VariantVisitor < ' de > > ( self , visitor : V ) -> Result < ( V :: Output , Self :: Variant ) , Self :: Error > {
346350 // Read the `tag` property in JS.
@@ -362,8 +366,8 @@ impl<'de, 'a, 's: 'de> de::SumAccess<'de> for SumAccess<'a, 's> {
362366 }
363367}
364368
365- impl < ' de , ' a , ' s : ' de > de:: VariantAccess < ' de > for Deserializer < ' a , ' s > {
366- type Error = Error < ' s > ;
369+ impl < ' de , ' this , ' scope : ' de > de:: VariantAccess < ' de > for Deserializer < ' this , ' scope > {
370+ type Error = Error < ' scope > ;
367371
368372 fn deserialize_seed < T : de:: DeserializeSeed < ' de > > ( self , seed : T ) -> Result < T :: Output , Self :: Error > {
369373 seed. deserialize ( self )
@@ -372,18 +376,18 @@ impl<'de, 'a, 's: 'de> de::VariantAccess<'de> for Deserializer<'a, 's> {
372376
373377/// Used by an `ArrayVisitor` to deserialize every element of a JS array
374378/// to a SATS array.
375- struct ArrayAccess < ' a , ' s , T > {
376- common : DeserializerCommon < ' a , ' s > ,
377- arr : Local < ' s , Array > ,
379+ struct ArrayAccess < ' this , ' scope , T > {
380+ common : DeserializerCommon < ' this , ' scope > ,
381+ arr : Local < ' scope , Array > ,
378382 seeds : RepeatN < T > ,
379383 index : u32 ,
380384}
381385
382- impl < ' de , ' a , ' s , T > ArrayAccess < ' a , ' s , T >
386+ impl < ' de , ' this , ' scope , T > ArrayAccess < ' this , ' scope , T >
383387where
384388 T : DeserializeSeed < ' de > + Clone ,
385389{
386- fn new ( arr : Local < ' s , Array > , common : DeserializerCommon < ' a , ' s > , seed : T ) -> Self {
390+ fn new ( arr : Local < ' scope , Array > , common : DeserializerCommon < ' this , ' scope > , seed : T ) -> Self {
387391 Self {
388392 arr,
389393 common,
@@ -393,9 +397,9 @@ where
393397 }
394398}
395399
396- impl < ' de , ' s : ' de , T : DeserializeSeed < ' de > + Clone > de:: ArrayAccess < ' de > for ArrayAccess < ' _ , ' s , T > {
400+ impl < ' de , ' scope : ' de , T : DeserializeSeed < ' de > + Clone > de:: ArrayAccess < ' de > for ArrayAccess < ' _ , ' scope , T > {
397401 type Element = T :: Output ;
398- type Error = Error < ' s > ;
402+ type Error = Error < ' scope > ;
399403
400404 fn next_element ( & mut self ) -> Result < Option < Self :: Element > , Self :: Error > {
401405 self . seeds
0 commit comments