@@ -12,6 +12,26 @@ pub struct Document<'a, T: Text<'a>>
12
12
pub definitions : Vec < Definition < ' a , T > > ,
13
13
}
14
14
15
+ impl < ' a > Document < ' a , String > {
16
+ pub fn into_static ( self ) -> Document < ' static , String > {
17
+ // To support both reference and owned values in the AST,
18
+ // all string data is represented with the ::common::Str<'a, T: Text<'a>>
19
+ // wrapper type.
20
+ // This type must carry the liftetime of the schema string,
21
+ // and is stored in a PhantomData value on the Str type.
22
+ // When using owned String types, the actual lifetime of
23
+ // the Ast nodes is 'static, since no references are kept,
24
+ // but the nodes will still carry the input lifetime.
25
+ // To continue working with Document<String> in a owned fasion
26
+ // the lifetime needs to be transmuted to 'static.
27
+ //
28
+ // This is safe because no references are present.
29
+ // Just the PhantomData lifetime reference is transmuted away.
30
+ unsafe { std:: mem:: transmute :: < _ , Document < ' static , String > > ( self ) }
31
+ }
32
+ }
33
+
34
+
15
35
#[ derive( Debug , Clone , PartialEq ) ]
16
36
pub enum Definition < ' a , T : Text < ' a > > {
17
37
SchemaDefinition ( SchemaDefinition < ' a , T > ) ,
0 commit comments