@@ -40,46 +40,25 @@ impl<'a, 'types> Context<'a, 'types> {
4040 self . namespaces . last ( )
4141 }
4242
43- pub ( super ) fn new (
44- meta : & ' a MetaData < ' types > ,
45- ident : & ' a TypeIdent ,
46- state : & ' a mut State < ' types > ,
47- ) -> Self {
48- let reachable = state. loop_detection . get_reachable ( & state. cache , ident) ;
49-
50- Self {
51- meta,
52- ident,
53- state,
54- reachable,
55- namespaces : Vec :: new ( ) ,
56- }
57- }
58-
59- pub ( super ) fn current_module ( & self ) -> ModuleIdent {
60- ModuleIdent :: new (
61- self . meta . types ,
62- self . ident ,
63- self . check_generator_flags ( GeneratorFlags :: USE_NAMESPACE_MODULES ) ,
64- self . check_generator_flags ( GeneratorFlags :: USE_SCHEMA_MODULES ) ,
65- )
66- }
67-
68- pub ( super ) fn current_type_ref ( & self ) -> & TypeRef {
69- self . state . cache . get ( self . ident ) . unwrap ( )
70- }
71-
72- pub ( super ) fn get_trait_infos ( & mut self ) -> & TraitInfos {
73- & self . state . trait_infos
74- }
75-
76- pub ( super ) fn get_or_create_type_ref ( & mut self , ident : & TypeIdent ) -> Result < & TypeRef , Error > {
43+ /// Get the [`TypeRef`] for the passed `ident`, creating it (and scheduling
44+ /// the type for generation) if it does not exist yet.
45+ ///
46+ /// # Errors
47+ ///
48+ /// Forwards the errors raised while creating the type reference.
49+ pub fn get_or_create_type_ref ( & mut self , ident : & TypeIdent ) -> Result < & TypeRef , Error > {
7750 let type_ref = self . state . get_or_create_type_ref_mut ( self . meta , ident) ?;
7851
7952 Ok ( type_ref)
8053 }
8154
82- pub ( super ) fn get_or_create_type_ref_for_value (
55+ /// Like [`get_or_create_type_ref`](Self::get_or_create_type_ref), but also
56+ /// marks the type as reachable by value if `by_value` is set.
57+ ///
58+ /// # Errors
59+ ///
60+ /// Forwards the errors raised while creating the type reference.
61+ pub fn get_or_create_type_ref_for_value (
8362 & mut self ,
8463 ident : & TypeIdent ,
8564 by_value : bool ,
@@ -93,7 +72,14 @@ impl<'a, 'types> Context<'a, 'types> {
9372 Ok ( type_ref)
9473 }
9574
96- pub ( super ) fn get_or_create_type_ref_for_element (
75+ /// Like [`get_or_create_type_ref`](Self::get_or_create_type_ref), but for an
76+ /// element. Returns the [`TypeRef`] together with a flag that indicates if
77+ /// the type needs to be boxed.
78+ ///
79+ /// # Errors
80+ ///
81+ /// Forwards the errors raised while creating the type reference.
82+ pub fn get_or_create_type_ref_for_element (
9783 & mut self ,
9884 ident : & TypeIdent ,
9985 by_value : bool ,
@@ -108,6 +94,38 @@ impl<'a, 'types> Context<'a, 'types> {
10894 Ok ( ( type_ref, boxed) )
10995 }
11096
97+ pub ( super ) fn new (
98+ meta : & ' a MetaData < ' types > ,
99+ ident : & ' a TypeIdent ,
100+ state : & ' a mut State < ' types > ,
101+ ) -> Self {
102+ let reachable = state. loop_detection . get_reachable ( & state. cache , ident) ;
103+
104+ Self {
105+ meta,
106+ ident,
107+ state,
108+ reachable,
109+ namespaces : Vec :: new ( ) ,
110+ }
111+ }
112+
113+ pub ( super ) fn current_module ( & self ) -> ModuleIdent {
114+ ModuleIdent :: new (
115+ self . meta . types ,
116+ self . ident ,
117+ self . check_generator_flags ( GeneratorFlags :: USE_NAMESPACE_MODULES ) ,
118+ self . check_generator_flags ( GeneratorFlags :: USE_SCHEMA_MODULES ) ,
119+ )
120+ }
121+
122+ pub ( super ) fn current_type_ref ( & self ) -> & TypeRef {
123+ self . state . cache . get ( self . ident ) . unwrap ( )
124+ }
125+
126+ pub ( super ) fn get_trait_infos ( & mut self ) -> & TraitInfos {
127+ & self . state . trait_infos
128+ }
111129 pub ( super ) fn make_trait_impls ( & mut self ) -> Result < Vec < TokenStream > , Error > {
112130 let ident = self . ident . clone ( ) ;
113131 let current_module = self . current_module ( ) ;
0 commit comments