Skip to content

Commit 885aa8c

Browse files
authored
feat: Call FunctionBuilder::add_{in,out}put for any AsMut<Hugr> (#2376)
Missed this when updating the builder; the methods `FunctionBuilder::add_input` and `::add_output` are restricted to `FunctionBuilder<Hugr>` but they could as well be used for any `AsMut<Hugr>`.
1 parent 292af80 commit 885aa8c

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

hugr-core/src/builder/dataflow.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,31 @@ impl FunctionBuilder<Hugr> {
170170
let db = DFGBuilder::create_with_io(base, root, body)?;
171171
Ok(Self::from_dfg_builder(db))
172172
}
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+
}
173198

174199
/// Add a new input to the function being constructed.
175200
///
@@ -259,31 +284,6 @@ impl FunctionBuilder<Hugr> {
259284
}
260285
}
261286

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-
287287
impl<B: AsMut<Hugr> + AsRef<Hugr>, T> Container for DFGWrapper<B, T> {
288288
#[inline]
289289
fn container_node(&self) -> Node {

0 commit comments

Comments
 (0)