Skip to content

Commit

Permalink
feat: Derive things for builder structs (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
aborgna-q authored Jun 29, 2023
1 parent 04ecd83 commit 774e342
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/builder/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::{hugr::HugrMut, types::TypeRow, Hugr};

/// Builder for a [`crate::ops::CFG`] child control
/// flow graph
#[derive(Debug, PartialEq)]
pub struct CFGBuilder<T> {
pub(super) base: T,
pub(super) cfg_node: Node,
Expand Down
2 changes: 2 additions & 0 deletions src/builder/circuit_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ use crate::Wire;
/// Builder to build regions of dataflow graphs that look like Circuits,
/// where some inputs of operations directly correspond to some outputs.
/// Allows appending operations by indexing a vector of input wires.
#[derive(Debug, PartialEq)]
pub struct CircuitBuilder<'a, T: ?Sized> {
wires: Vec<Wire>,
builder: &'a mut T,
}

/// Enum for specifying a [`CircuitBuilder`] input wire using either an index to
/// the builder vector of wires, or an arbitrary other wire.
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum AppendWire {
/// Arbitrary input wire.
W(Wire),
Expand Down
1 change: 1 addition & 0 deletions src/builder/conditional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub enum ConditionalBuildError {
}

/// Builder for a [`ops::Conditional`] node's children.
#[derive(Debug, Clone, PartialEq)]
pub struct ConditionalBuilder<T> {
pub(super) base: T,
pub(super) conditional_node: Node,
Expand Down
2 changes: 2 additions & 0 deletions src/builder/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::Node;
use crate::{hugr::HugrMut, Hugr};

/// Builder for a [`ops::DFG`] node.
#[derive(Debug, Clone, PartialEq)]
pub struct DFGBuilder<T> {
pub(crate) base: T,
pub(crate) dfg_node: Node,
Expand Down Expand Up @@ -115,6 +116,7 @@ impl<T: AsMut<Hugr> + AsRef<Hugr>> Dataflow for DFGBuilder<T> {

/// Wrapper around [`DFGBuilder`] used to build other dataflow regions.
// Stores option of DFGBuilder so it can be taken out without moving.
#[derive(Debug, Clone, PartialEq)]
pub struct DFGWrapper<B, T>(DFGBuilder<B>, PhantomData<T>);

impl<B, T> DFGWrapper<B, T> {
Expand Down
1 change: 1 addition & 0 deletions src/builder/module_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use smol_str::SmolStr;
use crate::{hugr::HugrMut, Hugr};

/// Builder for a HUGR module.
#[derive(Debug, Clone, PartialEq)]
pub struct ModuleBuilder<T>(pub(super) T);

impl<T: AsMut<Hugr> + AsRef<Hugr>> Container for ModuleBuilder<T> {
Expand Down

0 comments on commit 774e342

Please sign in to comment.