@@ -170,6 +170,31 @@ impl FunctionBuilder<Hugr> {
170
170
let db = DFGBuilder :: create_with_io ( base, root, body) ?;
171
171
Ok ( Self :: from_dfg_builder ( db) )
172
172
}
173
+ }
174
+
175
+ impl < B : AsMut < Hugr > + AsRef < Hugr > > FunctionBuilder < B > {
176
+ /// Initialize a new function definition on the root module of an existing HUGR.
177
+ ///
178
+ /// The HUGR's entrypoint will **not** be modified.
179
+ ///
180
+ /// # Errors
181
+ ///
182
+ /// Error in adding DFG child nodes.
183
+ pub fn with_hugr (
184
+ mut hugr : B ,
185
+ name : impl Into < String > ,
186
+ signature : impl Into < PolyFuncType > ,
187
+ ) -> Result < Self , BuildError > {
188
+ let signature: PolyFuncType = signature. into ( ) ;
189
+ let body = signature. body ( ) . clone ( ) ;
190
+ let op = ops:: FuncDefn :: new ( name, signature) ;
191
+
192
+ let module = hugr. as_ref ( ) . module_root ( ) ;
193
+ let func = hugr. as_mut ( ) . add_node_with_parent ( module, op) ;
194
+
195
+ let db = DFGBuilder :: create_with_io ( hugr, func, body) ?;
196
+ Ok ( Self :: from_dfg_builder ( db) )
197
+ }
173
198
174
199
/// Add a new input to the function being constructed.
175
200
///
@@ -259,31 +284,6 @@ impl FunctionBuilder<Hugr> {
259
284
}
260
285
}
261
286
262
- impl < B : AsMut < Hugr > + AsRef < Hugr > > FunctionBuilder < B > {
263
- /// Initialize a new function definition on the root module of an existing HUGR.
264
- ///
265
- /// The HUGR's entrypoint will **not** be modified.
266
- ///
267
- /// # Errors
268
- ///
269
- /// Error in adding DFG child nodes.
270
- pub fn with_hugr (
271
- mut hugr : B ,
272
- name : impl Into < String > ,
273
- signature : impl Into < PolyFuncType > ,
274
- ) -> Result < Self , BuildError > {
275
- let signature: PolyFuncType = signature. into ( ) ;
276
- let body = signature. body ( ) . clone ( ) ;
277
- let op = ops:: FuncDefn :: new ( name, signature) ;
278
-
279
- let module = hugr. as_ref ( ) . module_root ( ) ;
280
- let func = hugr. as_mut ( ) . add_node_with_parent ( module, op) ;
281
-
282
- let db = DFGBuilder :: create_with_io ( hugr, func, body) ?;
283
- Ok ( Self :: from_dfg_builder ( db) )
284
- }
285
- }
286
-
287
287
impl < B : AsMut < Hugr > + AsRef < Hugr > , T > Container for DFGWrapper < B , T > {
288
288
#[ inline]
289
289
fn container_node ( & self ) -> Node {
0 commit comments