@@ -34,7 +34,19 @@ impl InitHandle {
3434 where
3535 C : NativeClassMethods + StaticallyNamed ,
3636 {
37- self . add_maybe_tool_class_as :: < C > ( Cow :: Borrowed ( C :: CLASS_NAME ) , false )
37+ self . add_class_with :: < C > ( |_| { } )
38+ }
39+
40+ /// Registers a new class to the engine.
41+ #[ inline]
42+ pub fn add_class_with < C > ( self , f : impl FnOnce ( & ClassBuilder < C > ) )
43+ where
44+ C : NativeClassMethods + StaticallyNamed ,
45+ {
46+ self . add_maybe_tool_class_as_with :: < C > ( Cow :: Borrowed ( C :: CLASS_NAME ) , false , |builder| {
47+ C :: nativeclass_register_monomorphized ( builder) ;
48+ f ( builder) ;
49+ } )
3850 }
3951
4052 /// Registers a new tool class to the engine.
@@ -43,7 +55,19 @@ impl InitHandle {
4355 where
4456 C : NativeClassMethods + StaticallyNamed ,
4557 {
46- self . add_maybe_tool_class_as :: < C > ( Cow :: Borrowed ( C :: CLASS_NAME ) , true )
58+ self . add_tool_class_with :: < C > ( |_| { } )
59+ }
60+
61+ /// Registers a new tool class to the engine.
62+ #[ inline]
63+ pub fn add_tool_class_with < C > ( self , f : impl FnOnce ( & ClassBuilder < C > ) )
64+ where
65+ C : NativeClassMethods + StaticallyNamed ,
66+ {
67+ self . add_maybe_tool_class_as_with :: < C > ( Cow :: Borrowed ( C :: CLASS_NAME ) , true , |builder| {
68+ C :: nativeclass_register_monomorphized ( builder) ;
69+ f ( builder) ;
70+ } )
4771 }
4872
4973 /// Registers a new class to the engine
@@ -55,7 +79,19 @@ impl InitHandle {
5579 where
5680 C : NativeClassMethods ,
5781 {
58- self . add_maybe_tool_class_as :: < C > ( Cow :: Owned ( name) , false )
82+ self . add_class_as_with :: < C > ( name, |_| { } )
83+ }
84+
85+ /// Registers a new class to the engine
86+ ///
87+ /// If the type implements [`StaticallyTyped`], that name is ignored in favor of the
88+ /// name provided at registration.
89+ #[ inline]
90+ pub fn add_class_as_with < C > ( self , name : String , f : impl FnOnce ( & ClassBuilder < C > ) )
91+ where
92+ C : NativeClassMethods ,
93+ {
94+ self . add_maybe_tool_class_as_with :: < C > ( Cow :: Owned ( name) , false , f)
5995 }
6096
6197 /// Registers a new tool class to the engine
@@ -67,13 +103,29 @@ impl InitHandle {
67103 where
68104 C : NativeClassMethods ,
69105 {
70- self . add_maybe_tool_class_as :: < C > ( Cow :: Owned ( name) , true )
106+ self . add_tool_class_as_with :: < C > ( name, |_| { } )
71107 }
72108
109+ /// Registers a new tool class to the engine
110+ ///
111+ /// If the type implements [`StaticallyTyped`], that name is ignored in favor of the
112+ /// name provided at registration.
73113 #[ inline]
74- fn add_maybe_tool_class_as < C > ( self , name : Cow < ' static , str > , is_tool : bool )
114+ pub fn add_tool_class_as_with < C > ( self , name : String , f : impl FnOnce ( & ClassBuilder < C > ) )
75115 where
76116 C : NativeClassMethods ,
117+ {
118+ self . add_maybe_tool_class_as_with :: < C > ( Cow :: Owned ( name) , true , f)
119+ }
120+
121+ #[ inline]
122+ fn add_maybe_tool_class_as_with < C > (
123+ self ,
124+ name : Cow < ' static , str > ,
125+ is_tool : bool ,
126+ f : impl FnOnce ( & ClassBuilder < C > ) ,
127+ ) where
128+ C : NativeClassMethods ,
77129 {
78130 let c_class_name = CString :: new ( & * name) . unwrap ( ) ;
79131
@@ -202,6 +254,8 @@ impl InitHandle {
202254
203255 // register methods
204256 C :: nativeclass_register ( & builder) ;
257+
258+ f ( & builder) ;
205259 }
206260 }
207261}
0 commit comments