Skip to main content

BlockGraph

Struct BlockGraph 

Source
pub struct BlockGraph {
    pub name: String,
    pub interface: ModuleInterface,
    pub instances: Vec<ModuleInstance>,
    pub quantum_connections: Vec<QuantumConnection>,
    pub bit_bindings: Vec<BitBinding>,
    /* private fields */
}
Expand description

A graph of surface code blocks connected by lattice-surgery pipes.

This is the source-level, authoring representation: blocks sit at integer 3D lattice positions (the z axis is time), pipes connect adjacent endpoints, and classical control flow lives in a cached ActionDag. Structural edits refresh that DAG; metadata-only tag edits leave it intact. validate rebuilds and checks both structure and action semantics.

Fields§

§name: String

Definition name, main for the executable root.

§interface: ModuleInterface

Public quantum and classical interface.

§instances: Vec<ModuleInstance>

Rotated and translated references to other graph definitions.

§quantum_connections: Vec<QuantumConnection>

Authored quantum seams between local blocks and child instances.

§bit_bindings: Vec<BitBinding>

Authored bindings to child classical inputs.

Implementations§

Source§

impl BlockGraph

Source

pub fn try_add_branches( &mut self, branches: impl IntoIterator<Item = Branch>, shared_pipes: impl IntoIterator<Item = Pipe>, actions: impl IntoIterator<Item = Action>, ) -> Result<(), BlockGraphError>

Attaches branches, shared seams, and additional actions in one edit. Resolve actions are created from each branch’s condition. Existing actions are retained. All geometry, names, interfaces, and action dependencies are checked before changing the graph.

§Errors

Returns an error for invalid geometry or actions, leaving self unchanged.

§Examples
use bloq_graph::{BlockGraph, Branch, BranchArm, Expr, Pipe, Direction};
let mut graph = BlockGraph::from_text("BLOG 1.0\nmodule main {\n0: ZXZ [0,0,0]\n1: ZXZ [2,0,0]\nm = measure 1\n}")?;
let arm = BranchArm::try_from_blocks([([0, 0, 1], "Z")])?;
graph.try_add_branches(
    [Branch::new("cap", Expr::Var("m".into()), arm.clone(), arm)],
    [Pipe::new([0, 0, 0], Direction::ZPLUS)],
    [],
)?;
assert_eq!(graph.branch_regions()?.len(), 1);
Source

pub fn try_add_branch_region( &mut self, name: impl Into<String>, on_false: BranchArm, on_true: BranchArm, ) -> Result<IVec3, BlockGraphError>

Adds a named explicit terminal region and shows its true arm.

§Errors

Returns an error if the region name, geometry, seams, or actions are invalid.

Source

pub fn try_add_branch_regions( &mut self, regions: Vec<(String, BranchArm, BranchArm)>, shared_pipes: Vec<Pipe>, ) -> Result<Vec<IVec3>, BlockGraphError>

Install disjoint region owners together, then resolve their common seams. Shared pipes remain in the common graph and are never copied into arms.

§Errors

Returns an error if any region, shared pipe, or resulting action graph is invalid.

Source

pub fn has_continuing_branches(&self) -> bool

Whether any region reconnects to spatial neighbors or later common code.

Source

pub fn take_branch_arm( &mut self, positions: impl IntoIterator<Item = IVec3>, pipe_endpoints: impl IntoIterator<Item = (IVec3, IVec3)>, ) -> Result<BranchArm, BlockGraphError>

Captures selected blocks and their explicitly selected incident pipes, removing them from the currently visible graph.

§Errors

Returns an error if a selected element is missing or the selection is not a closed arm.

Source

pub fn restore_branch_arm( &mut self, arm: &BranchArm, ) -> Result<(), BlockGraphError>

Restores a previously captured loose arm to the visible graph.

§Errors

Returns an error if the arm conflicts with existing geometry or actions.

Source

pub fn branch_definitions(&self) -> &[BranchRegion]

Returns explicit branch definitions in declaration order.

Source

pub fn branch_by_name(&self, name: &str) -> Option<&BranchRegion>

Finds an explicit branch definition by public name.

Source

pub fn branch_by_target(&self, target: IVec3) -> Option<&BranchRegion>

Finds an explicit branch definition by stable internal anchor.

Source

pub fn shown_branch_at(&self, position: IVec3) -> Option<&BranchRegion>

Returns the displayed region owning position, for scene picking.

Source

pub fn set_shown_branch_arm( &mut self, name: &str, show_true: bool, ) -> Result<(), BlockGraphError>

Switches which arm is materialized for display.

§Errors

Returns an error if the branch is unknown or the selected arm cannot be materialized.

Source

pub fn branch_regions(&self) -> Result<Vec<BranchRegion>, BlockGraphError>

Returns explicit regions in resolve-action order.

§Errors

Returns an error if branch actions and stored regions disagree.

Source

pub fn branch_projections( &self, ) -> Result<Vec<BranchProjection>, BlockGraphError>

Projects every reachable explicit branch assignment.

§Errors

Returns an error if branch validation, enumeration, or materialization fails.

Source

pub fn project_branches( &self, assignments: impl IntoIterator<Item = (IVec3, bool)>, ) -> Result<Self, BlockGraphError>

Projects every explicit branch to an ordinary static graph.

§Errors

Returns an error for missing assignments or an invalid projected graph.

Source§

impl BlockGraph

Source

pub fn place_module( &mut self, name: &str, definition: &str, ) -> Result<IVec3, BlockGraphError>

Places a child beside the current geometry and exposes its public interface. Quantum ports, classical inputs, and classical outputs receive instance-qualified names. The graph is unchanged on failure.

§Errors

Returns a declaration, geometry, coordinate, or certification error.

Source

pub fn place_module_with( &mut self, name: &str, definition: &str, translation: Option<IVec3>, rotation: ModuleRotation, ) -> Result<IVec3, BlockGraphError>

Places a child with optional explicit translation and a local rotation. When translation is absent, the child is placed beside the current geometry.

§Errors

Returns a declaration, geometry, coordinate, or certification error without changing the graph.

Source

pub fn connect_modules( &mut self, output: &str, input: &str, ) -> Result<usize, BlockGraphError>

Aligns and docks two named child ports, joining all other touching compatible ports. Names use instance.port. Connected input-side instances move together. Direct seams preserve the endpoint Hadamards; obstructed compaction retains connection cubes.

§Errors

Returns a declaration, geometry, coordinate, or certification error without changing the graph.

Source

pub fn connect_modules_with( &mut self, output: &str, input: &str, options: ModuleJoinOptions, ) -> Result<usize, BlockGraphError>

Docks named child ports with explicit alignment, compaction, and Hadamard preferences.

§Errors

Returns a declaration, geometry, coordinate, or certification error without changing the graph.

Source

pub fn bind_modules( &mut self, source: &str, target: &str, ) -> Result<(), BlockGraphError>

Binds a parent value or child bit output to a child’s classical input. Replaces its existing binding and removes an unused automatically exposed parent input.

§Errors

Returns a declaration, dependency, or certification error without changing the graph.

Source

pub fn translate_module( &mut self, name: &str, offset: IVec3, compact: bool, ) -> Result<IVec3, BlockGraphError>

Translates an instance’s connected group and joins touching compatible free ports. Returns the applied offset, including any successful seam compaction.

§Errors

Returns a declaration, geometry, coordinate, or certification error without changing the graph.

Source§

impl BlockGraph

Source

pub fn replace_local_body(&mut self, body: Self)

Replaces local geometry and actions while retaining interfaces and definitions.

Source§

impl BlockGraph

Source

pub fn new() -> Self

Creates an empty block graph.

Source

pub fn infer_pipe_basis(&self, pipe: &Pipe) -> [Option<Basis>; 3]

Infers the X/Y/Z basis assignment for each face of a pipe from pipe.src.

Source

pub fn infer_pipe_basis_from_endpoint( &self, pipe: &Pipe, endpoint: IVec3, ) -> [Option<Basis>; 3]

Infers the X/Y/Z basis assignment for each face of a pipe from one endpoint.

Source

pub fn infer_spatial_port_cube_kind(&self, position: IVec3) -> Option<CubeKind>

Infers the unique non-spatial cube that continues a spatial Port into a plain temporal pipe.

The authored spatial pipe fixes the two bases perpendicular to its axis. The missing basis equals the temporal basis, leaving the other spatial axis as the cube normal.

Source

pub fn layer(&self, z: i32) -> BlockLayerView<'_>

Returns a read-only view of the time layer at z.

Source

pub fn cube_layer_components(&self) -> BTreeMap<i32, Vec<Vec<IVec3>>>

The +X/+Y connected components of each time layer’s cubes, keyed by the layer the cube is anchored in, each component sorted and the components ordered by their lowest member.

Spatial connectivity is the unit of shared time: merged patches drive the same data qubits, so anything schedule-like belongs to a whole component — the height propagated here, the CX-slot depth bloq_compile derives. +Z pipes are temporal and do not join components.

Source

pub fn action_graph(&self) -> &ActionDag

Returns the current action DAG.

Structural and action-affecting edits refresh this DAG; tag-only edits leave it intact.

Source

pub fn action_graph_error(&self) -> Option<&BlockGraphError>

Returns the error from the last failed DAG rebuild; Some means the cached DAG is an unvalidated best effort. Cleared by the next successful rebuild.

Source

pub fn analyze_action_graph(&self) -> Result<ActionDag, BlockGraphError>

Derives an independent action DAG, including correlation dependencies.

This inspection query does not change the source or compile physical IR. Authored hierarchies use the compiler’s module linker and correlation composition, retaining definition and instance ownership in each node. Continuing branches use the guarded causal readout planner. Composed and continuing-branch DAGs retain dependencies without assigning a single measurement stabilizer to each node.

§Errors

Returns an error for invalid sources, causal cycles, unavailable readouts, or exhausted analysis budgets.

Source

pub fn analyze_action_graph_with_limits( &self, limits: ModuleCertificationLimits, ) -> Result<ActionDag, BlockGraphError>

Derives an action DAG with explicit source-analysis resource limits.

§Errors

Returns the same typed failures as Self::analyze_action_graph, including exhaustion of the supplied budgets.

Source

pub fn actions(&self) -> Vec<Action>

Returns the actions in source order.

Source

pub fn has_actions(&self) -> bool

Returns true if the graph has any actions.

Source

pub fn get_block_id(&self, pos: impl Into<IVec3>) -> Option<u32>

Returns the internal node ID for the block at the given position.

Source

pub fn to_zx_graph(&self) -> Result<ZXGraph, BlockGraphError>

Converts this static block graph to a ZX-calculus graph.

A graph with structural Branch actions must first be expanded with BlockGraph::branch_projections; optional topology has no single ZX graph representation.

§Errors

Returns an error if graph validation or ZX conversion fails.

Source

pub fn stabilizers(&self) -> Result<StabilizerGenerators, BlockGraphError>

Derives the stabilizer generators for this graph via the unified compute backend.

Structural sources must first be expanded with BlockGraph::branch_projections; one generator table cannot describe several optional topologies.

§Errors

Returns an error if validation or stabilizer derivation fails.

Source

pub fn stabilizers_with_limits( &self, limits: ModuleCertificationLimits, ) -> Result<StabilizerGenerators, BlockGraphError>

Derive a static table with explicit construction and search limits.

§Errors

Returns an error if validation, resource limits, or stabilizer derivation fails.

Source

pub fn with_analyzed_action_graph( self, stabilizers: &StabilizerGenerators, ) -> Result<Self, BlockGraphError>

Rebuilds the action DAG with stabilizer-derived dependencies and surfaces.

stabilizers must come from this graph. The returned graph stores only derived metadata; BLOG serialization remains unchanged.

§Errors

Returns an error if action validation or readout dependency attachment fails.

Source

pub fn analyze_actions( self, ) -> Result<(Self, StabilizerGenerators), BlockGraphError>

Computes stabilizers once and installs their derived action analysis.

For a graph with structural branches, the returned table is only the canonical all-true, common-prefix analysis table used by the compiler; it is not the stabilizer family of the conditional graph. Use BlockGraph::branch_projections and derive each projection’s stabilizers for semantic inspection.

§Errors

Returns an error if stabilizer derivation or action analysis fails.

Source

pub fn analyze_actions_with_limits( self, limits: ModuleCertificationLimits, ) -> Result<(Self, StabilizerGenerators), BlockGraphError>

Analyze source actions without replacing explicit resource limits with defaults.

§Errors

Returns an error if resource-limited stabilizer derivation or action analysis fails.

Source

pub fn fill_ports_auto( &self, ) -> Result<Vec<(BlockGraph, Vec<StabilizerGenerator>)>, BlockGraphError>

Fills port blocks using compatible external stabilizer support and returns each closed graph with the generators that selected its fill. Static variants retain selected measurement records and their aliases, removing feedback and resolves for filled caps. Returns an error if postselection or a structural branch needs an unselected record.

§Errors

Returns an error if automatic filling or postselection validation fails.

Source

pub fn fill_ports_auto_with_limits( &self, limits: ModuleCertificationLimits, ) -> Result<Vec<(BlockGraph, Vec<StabilizerGenerator>)>, BlockGraphError>

Fills ports with explicit limits for source and filled-graph analysis.

§Errors

Returns the same errors as fill_ports_auto, including exhaustion of a caller’s certification budget.

Source

pub fn filled_graphs(&self) -> Result<Vec<BlockGraph>, BlockGraphError>

The closed graphs fill_ports_auto produces, without the generators that selected each fill.

§Errors

Returns the same automatic-filling errors as Self::fill_ports_auto.

Source

pub fn filled_graphs_with_limits( &self, limits: ModuleCertificationLimits, ) -> Result<Vec<BlockGraph>, BlockGraphError>

The graphs from fill_ports_auto_with_limits, without their selecting stabilizer generators.

§Errors

Returns the same errors as Self::fill_ports_auto_with_limits.

Source

pub fn spans( &self, ) -> Option<(RangeInclusive<i32>, RangeInclusive<i32>, RangeInclusive<i32>)>

Returns the inclusive coordinate span of the graph on each axis, including both stored arms of every branch, or None when empty.

Source

pub fn randomly_resolve_selectives( &self, seed: u64, ) -> Result<(BlockGraph, HashMap<Block, Block>), BlockGraphError>

Resolve all selective blocks from one random assignment of their action measurement variables. Resolve expressions that share a variable are therefore sampled jointly; sites without actions retain independent random choices. Returns the resolved graph and a map from original to resolved blocks. Resolution is deterministic in seed. Authored module sources must be explicitly flattened first.

If at least one selective is resolved, the result is structure-only and all actions are removed, including structural branches. Project branches first when a concrete conditional topology is required.

§Panics

Panics if internally cached resolve metadata names a non-selective block.

§Errors

Returns a typed hierarchy error unless child instances are explicitly flattened.

Source

pub fn add_action(&mut self, action: Action) -> Result<(), BlockGraphError>

Appends an action, revalidating and re-analyzing the whole action set against the graph. See set_actions.

§Errors

Returns a BlockGraphError if the resulting action set fails validation or physical analysis.

Source

pub fn set_actions( &mut self, actions: Vec<Action>, ) -> Result<(), BlockGraphError>

Replaces all actions, validating the new set against the graph and, once the topology is structurally complete, deriving each measurement’s stabilizer surface and its implicit dependency edges.

§Errors

Returns a BlockGraphError if the new action set fails semantic or graph-constraint validation, a measurement surface is unavailable, or the derived edges close a dependency cycle; the previous actions are left in place.

Source

pub fn set_actions_with_inputs( &mut self, actions: Vec<Action>, inputs: impl IntoIterator<Item = String>, ) -> Result<(), BlockGraphError>

Replaces actions while declaring external Boolean inputs.

Module bodies use these names for values bound by their parent. A standalone graph compiler has no producer for them.

§Errors

Returns the same errors as set_actions, plus InvalidActionError::InvalidActionName for an invalid input name.

Source

pub fn set_actions_deferred( &mut self, actions: Vec<Action>, ) -> Result<(), BlockGraphError>

Replaces actions after source validation, deferring stabilizer surfaces and implicit dependencies to analyze_actions.

§Errors

Returns a BlockGraphError for invalid source semantics without changing the previous actions.

Source

pub fn set_actions_lenient( &mut self, actions: Vec<Action>, ) -> Result<(), BlockGraphError>

Replaces all actions without failing on a graph-constraint violation, recording it in action_graph_error instead.

This supports incremental editing, where an action list can be temporarily incomplete. Names and nonempty feedback targets remain strict so actions can survive a BLOG round-trip.

Callers that must not install a broken action set use set_actions.

§Errors

Returns BlockGraphError if a Measure/Let name is invalid or feedback has no targets; the previous actions are left in place.

Source

pub fn clear_actions(&mut self)

Removes all actions.

Source

pub fn shift_positions(&self, offset: IVec3) -> Result<Self, BlockGraphError>

Returns a new BlockGraph shifted by the given offset.

§Errors

Returns BlockGraphError::CoordinateOverflow if any shifted block footprint, pipe endpoint, or action position exceeds the coordinate range.

Source

pub fn rotate_about_origin( &self, axis: UDirection, quarter_turns: i32, ) -> Result<Self, BlockGraphError>

Returns a new BlockGraph rotated around the origin along the given axis.

Rotation preserves blocks, pipes, branches, and actions. Rotations that cannot represent a block’s time-oriented geometry return a typed error.

§Errors

Returns an unsupported-orientation, coordinate, or validation error.

Source

pub fn rotate_about_origin_lenient( &self, axis: UDirection, quarter_turns: i32, ) -> Result<Self, BlockGraphError>

Rotates the graph without validating the result.

§Errors

Returns an unsupported-orientation or coordinate-overflow error.

Source

pub fn flip_xz_basis_lenient(&self) -> Result<Self, BlockGraphError>

Returns a new BlockGraph with X/Z bases flipped.

Swaps block and feedback bases and negates selective resolve conditions to preserve their ordered choices in the canonical XY/XZ/YZ representation. Fixed T/Y resources retain their kind; each incident pipe toggles its Hadamard. A selective’s Y arm also needs its outcome sign flipped because H conjugation sends Y to -Y; Pauli feedback along the other arm’s axis supplies that sign without changing its X/Z outcome. Positions, tags, and structural branch conditions are retained.

§Errors

Returns a flatten-required error for an authored module source.

Source

pub fn flip_xz_basis(&self) -> Result<Self, BlockGraphError>

Returns a validated copy with X/Z bases flipped, including the Hadamard frame on every fixed T/Y resource’s incident pipe and selective Y signs.

§Errors

Returns an error if the flipped graph or its actions are invalid.

Source

pub fn with_zero_min_z(&self) -> Result<Self, BlockGraphError>

Returns a new BlockGraph with all blocks shifted in the z-axis so that the minimum z-coordinate is zero.

§Errors

Returns BlockGraphError::CoordinateNormalizationOverflow if the normalized z span cannot be represented by i32 coordinates.

Source

pub fn is_empty(&self) -> bool

Returns true if this graph and every reachable definition contain no blocks. Both authored branch arms count. An unresolved definition returns false.

Source

pub fn block_count(&self) -> usize

Returns the number of blocks in this definition’s local geometry.

Source

pub fn pipe_count(&self) -> usize

Returns the number of pipes in this definition’s local geometry.

Source

pub fn walking_count(&self) -> usize

Returns the number of walking blocks in this definition’s local geometry.

Source

pub fn patch_rotation_count(&self) -> usize

Returns the number of patch rotation blocks in this definition’s local geometry.

Source

pub fn port_count(&self) -> usize

Returns the number of Port blocks in this definition’s local geometry.

Source

pub fn y_count(&self) -> usize

Returns the number of Y-basis blocks in this definition’s local geometry.

Source

pub fn t_count(&self) -> usize

Returns the number of T blocks in this definition’s local geometry.

Source

pub fn selective_count(&self) -> usize

Returns the number of selective blocks in this definition’s local geometry.

Source

pub fn blocks(&self) -> impl Iterator<Item = &Block>

Returns this definition’s local blocks, without expanding child instances.

Source

pub fn pipes(&self) -> impl Iterator<Item = &Pipe>

Returns this definition’s local pipes, without expanding child instances.

Source

pub fn pipes_at(&self, position: IVec3) -> impl Iterator<Item = &Pipe>

Pipes incident to the block anchored at position, including pipes at an extended block’s other endpoints. A missing anchor yields no pipes. Visits only the block’s adjacency, without scanning the graph.

Source

pub fn positions(&self) -> impl Iterator<Item = IVec3>

Returns local block positions, without expanding child instances.

Source

pub fn is_clifford(&self) -> bool

Returns true if every reachable definition and branch arm has no T blocks. An unresolved definition returns false.

Source

pub fn is_rigid(&self) -> bool

Returns true if every reachable definition and branch arm has a statically known block kind. An unresolved definition returns false.

Source

pub fn is_open(&self) -> bool

Returns true if the root has a public quantum boundary. Child Ports consumed by module seams do not make the root open.

Source

pub fn get_block(&self, position: impl Into<IVec3>) -> Option<&Block>

Returns a reference to the block at the given position, if it exists.

Source

pub fn get_endpoint_block(&self, position: impl Into<IVec3>) -> Option<&Block>

Returns the owning block for a connectable endpoint position.

For ordinary blocks this is the block at position; for extended blocks this also resolves the virtual end position back to the block stored at its start position.

Source

pub fn has_block_at(&self, position: impl Into<IVec3>) -> bool

Returns true if a block exists at the given position.

Source

pub fn has_endpoint_at(&self, position: impl Into<IVec3>) -> bool

Returns true if a connectable block endpoint exists at the given position.

Source

pub fn occupied_positions(&self) -> impl Iterator<Item = IVec3> + '_

Iterates over every lattice cell reserved by some block.

Source

pub fn can_place_block(&self, block: &Block) -> Result<(), BlockGraphError>

Checks whether block can be placed without an illegal footprint overlap.

§Errors

Returns BlockGraphError::BlockPositionOccupied if a reserved cell collides with an existing block that does not permit the overlap.

Source

pub fn set_cube_height( &mut self, position: IVec3, height: CubeHeight, ) -> Result<(), BlockGraphError>

Sets the cube height at position, re-checking the resulting footprint.

Height propagation can grow a cube from one cell to several, so the new footprint has to clear the same occupancy check a fresh placement would.

§Errors

BlockGraphError::BlockNotFound if nothing is placed at position, BlockGraphError::Block if the block is not a cube or the footprint leaves the coordinate range, or BlockGraphError::BlockPositionOccupied if the grown footprint collides.

§Panics

Panics if graph indexes change after the initial existence check.

Source

pub fn has_pipe_between(&self, u: impl Into<IVec3>, v: impl Into<IVec3>) -> bool

Returns true if a pipe exists between the two positions.

Source

pub fn set_block_kind( &mut self, position: impl Into<IVec3>, kind: BlockKind, ) -> Result<(), BlockGraphError>

Update a block kind while preserving graph indexes and refreshing action metadata.

§Errors

Returns an error if the block is missing or the new kind violates geometry or branch rules.

§Panics

Panics if graph indexes or an existing cube height are internally invalid.

Source

pub fn set_block_tag( &mut self, position: impl Into<IVec3>, tag: impl Into<String>, ) -> Result<(), BlockGraphError>

Update a block tag while preserving graph indexes and action metadata. An empty tag clears the tag.

§Errors

Returns BlockGraphError::BlockNotFound if no block occupies position, or BlockGraphError::InvalidTag if tag is malformed.

Source

pub fn set_port_color( &mut self, position: impl Into<IVec3>, rgb: [u8; 3], ) -> Result<(), BlockGraphError>

Updates a Port’s RGB display color. Alpha remains fixed; default gray is omitted from serialization.

§Errors

Returns BlockGraphError::BlockNotFound if no block occupies position, or BlockError::PortColorOnNonPort if that block is not a Port.

Source

pub fn set_port_role( &mut self, position: impl Into<IVec3>, role: PortRole, ) -> Result<(), BlockGraphError>

Assigns the role of a Port block.

§Errors

Returns an error if the block is missing or is not a Port.

Source

pub fn add_block(&mut self, block: Block) -> IVec3

Add a block to the graph, returning its position.

This mutates topology and refreshes cached action metadata for any existing actions.

§Panics

Panics if the block’s position is already occupied. Use try_add_block for a fallible alternative.

Source

pub fn try_add_block(&mut self, block: Block) -> Result<IVec3, BlockGraphError>

Adds a block to the graph, returning its position or an error if the position is occupied.

This mutates topology and refreshes cached action metadata for any existing actions.

§Errors

Returns an error for an occupied or unrepresentable block footprint.

Source

pub fn remove_block(&mut self, pos: impl Into<IVec3>) -> Option<Block>

Removes and returns the block at the given position, if it exists.

This mutates topology and refreshes cached action metadata for any existing actions.

Source

pub fn add_pipe(&mut self, pipe: Pipe)

Add a pipe connecting two blocks.

This mutates topology and refreshes cached action metadata for any existing actions.

§Panics

Panics if either endpoint does not exist or if the pipe already exists. Use try_add_pipe for a fallible alternative.

Source

pub fn try_add_pipe(&mut self, pipe: Pipe) -> Result<(), BlockGraphError>

Adds a pipe connecting two blocks, returning an error if either endpoint is missing or the pipe already exists.

This mutates topology and refreshes cached action metadata for any existing actions.

§Errors

Returns an error for invalid endpoints, missing blocks, or a duplicate pipe.

Source

pub fn remove_pipe( &mut self, u: impl Into<IVec3>, v: impl Into<IVec3>, ) -> Option<Pipe>

Removes and returns the pipe between the two positions, if it exists.

Source

pub fn get_pipe( &self, u: impl Into<IVec3>, v: impl Into<IVec3>, ) -> Option<&Pipe>

Returns a reference to the pipe between the two positions, if it exists.

Source

pub fn get_pipe_between_blocks( &self, u: impl Into<IVec3>, v: impl Into<IVec3>, ) -> Option<&Pipe>

Returns the pipe connecting the blocks anchored at u and v.

Unlike get_pipe, this accepts block positions rather than physical pipe endpoints. This matters for multi-cell blocks whose connected endpoint is offset from the stored block position.

Source

pub fn set_pipe_tag( &mut self, u: impl Into<IVec3>, v: impl Into<IVec3>, tag: impl Into<String>, ) -> Result<(), BlockGraphError>

Update a pipe tag while preserving graph topology and action metadata. An empty tag clears the tag.

§Errors

Returns BlockGraphError::PipeNotFound if no pipe connects u and v, or BlockGraphError::InvalidTag if tag is malformed.

Source

pub fn set_pipe_hadamard( &mut self, u: impl Into<IVec3>, v: impl Into<IVec3>, hadamard: bool, ) -> Result<(), BlockGraphError>

Update a pipe Hadamard flag and refresh action metadata.

§Errors

Returns BlockGraphError::PipeNotFound if no pipe connects u and v.

Source

pub fn neighbors(&self, position: impl Into<IVec3>) -> Vec<&Block>

Returns all blocks directly connected to the block owning the given endpoint.

Source

pub fn neighbor_positions(&self, position: impl Into<IVec3>) -> Vec<IVec3>

Returns the physical neighbor endpoint positions for pipes attached to the given connectable endpoint.

Source

pub fn degree(&self, position: impl Into<IVec3>) -> usize

Returns the number of pipes attached to the given connectable endpoint.

Source

pub fn block_pairs_with_pipe( &self, ) -> impl Iterator<Item = (&Block, &Block, &Pipe)>

Returns an iterator over (block_u, block_v, pipe) triples for every pipe in the graph.

Source

pub fn pipe_endpoints_with_blocks( &self, ) -> impl Iterator<Item = (IVec3, IVec3, &Block, &Block, &Pipe)>

Returns physical endpoint positions and owner blocks for every pipe.

Source

pub fn validate(&self) -> Result<(), BlockGraphError>

Audits structure and source actions, including signed dependencies. Hierarchical graphs use composed certificates and their C0 contract; leaves retain the local stabilizer/action audit.

§Errors

Returns the first structural, action, or stabilizer-derived validation error.

Source

pub fn validate_structure(&self) -> Result<(), BlockGraphError>

Validates graph structural constraints without validating action semantics.

§Errors

Returns the first structural graph error.

Source

pub fn validate_source(&self) -> Result<(), BlockGraphError>

Validates graph structure and action-source semantics without deriving stabilizer surfaces or implicit physical dependencies.

§Errors

Returns the first structural or source-action error.

Source

pub fn structural_errors(&self) -> Vec<BlockGraphError>

Lists every structural violation rather than stopping at the first, for callers that need to tell a defect an edit introduced from one the graph already carried. An empty result means the same as BlockGraph::validate_structure returning Ok.

Violations are complete per validation phase, not across phases: an overlapping footprint or an unresolvable pipe endpoint suppresses the later geometry checks, which assume those hold.

Source§

impl BlockGraph

Source

pub fn write_module_gltf_file( &self, pipe_length: f32, path: impl AsRef<Path>, popped_faces: &[GltfFaceSelector], ) -> Result<(), BlockGraphError>

Exports an independent rendering projection colored by module definition.

Uses the editor’s opaque ownership colors and retains ordinary colors on cross-definition pipes. The authored hierarchy is unchanged.

§Errors

Returns a materialization, serialization, or file-I/O error.

Source

pub fn write_module_html_viewer( &self, pipe_length: f32, path: impl AsRef<Path>, popped_faces: &[GltfFaceSelector], ) -> Result<(), BlockGraphError>

Exports a module ownership view with independently toggled definition highlights.

Retains the authored graph and creates an independent flat rendering projection. The HTML embeds its model and loads model-viewer from a CDN.

§Errors

Returns a materialization, serialization, or file-I/O error.

Source

pub fn write_to_gltf_file( &self, pipe_length: f32, path: impl AsRef<Path>, stabilizer: Option<&StabilizerGenerator>, popped_faces: &[GltfFaceSelector], ) -> Result<(), BlockGraphError>

Exports the graph as a .gltf file, optionally overlaying a stabilizer generator.

Uses the editor’s orientation and baked diffuse lighting in unlit materials.

§Errors

Returns a graph, serialization, or file-I/O error.

Source

pub fn write_to_gltf_html_viewer( &self, pipe_length: f32, path: impl AsRef<Path>, stabilizer: Option<&StabilizerGenerator>, popped_faces: &[GltfFaceSelector], ) -> Result<(), BlockGraphError>

Exports the graph as an HTML viewer with an embedded glTF scene.

The model data is embedded as a base64 data URI, but the model-viewer renderer is loaded from a CDN, so the page requires network access.

§Errors

Returns a graph, serialization, or file-I/O error.

Source§

impl BlockGraph

Source

pub fn to_program_blog_text(&self) -> Result<String, ModuleError>

Serializes the complete executable hierarchy as BLOG.

Procedural graphs infer their interfaces; authored interfaces and helper definitions are retained exactly. Use to_blog_body_text explicitly for a local geometry/actions projection.

§Errors

Returns a typed error when a procedural graph’s interface cannot be inferred.

Source

pub fn to_blog_body_text(&self) -> String

Serializes the graph to the .blog text format (BLOG 1.0).

§Panics

Panics if internal block, pipe, branch, or action indexes are inconsistent.

Source

pub fn to_file(&self, path: impl AsRef<Path>) -> Result<(), BlockGraphError>

Writes the graph to a file in .blog text format.

§Errors

Returns BlockGraphError::Io if the file cannot be written.

Source

pub fn from_blog_text(blog_text: &str) -> Result<Self, BlockGraphError>

Parses a block graph from .blog text format.

BLOG is an authoring format, so the result may be structurally incomplete. Call Self::validate when a complete graph is required.

§Errors

Returns a parse or graph-construction error for invalid BLOG input.

Source

pub fn from_text(text: &str) -> Result<Self, BlockGraphError>

Parses executable BLOG or graph-body text, retaining module hierarchy.

This is the same input model as Python’s BlockGraph.from_text and the native compiler. Geometry, authored interfaces, child instances, seams, bindings, and helper definitions are owned by the returned graph. Imports require Self::load.

§Errors

Returns typed syntax, module, graph-construction, or resource-limit errors.

§Examples
use bloq_graph::BlockGraph;
let graph = BlockGraph::from_text("BLOG 1.0\nmodule main {\n0: ZXZ [0,0,0]\n}\n")?;
assert_eq!(graph.block_count(), 1);
Source

pub fn from_text_with_limits( text: &str, limits: ModuleCertificationLimits, ) -> Result<Self, BlockGraphError>

Parses executable BLOG or graph-body text with explicit source budgets.

The same limits govern action analysis and hierarchy expansion.

§Errors

Returns typed syntax, module, graph-construction, or resource-limit errors.

Source

pub fn load(path: impl AsRef<Path>) -> Result<Self, BlockGraphError>

Loads BLOG as a block graph, resolving imports relative to each file.

This matches Python’s BlockGraph.load. Module instances and interfaces remain authored; call Self::flatten explicitly when a consumer needs one expanded geometry projection.

§Errors

Returns typed I/O, parse, import-resolution, graph, or resource-limit errors.

Source

pub fn load_with_limits( path: impl AsRef<Path>, limits: ModuleCertificationLimits, ) -> Result<Self, BlockGraphError>

Loads BLOG as a graph with explicit source-analysis and expansion budgets.

The same limits apply to every imported hierarchy.

§Errors

Returns typed I/O, parse, import-resolution, graph, or resource-limit errors.

Source

pub fn fix_shadowed_faces(&self) -> Self

Returns a new graph with cube kinds adjusted so that shadowed pipe faces have consistent basis assignments.

Source§

impl BlockGraph

Source

pub const ENTRY_MODULE: &'static str = "main"

Required name of the executable root module.

Source

pub fn definition( name: impl Into<String>, body: Self, interface: ModuleInterface, instances: Vec<ModuleInstance>, quantum_connections: Vec<QuantumConnection>, bit_bindings: Vec<BitBinding>, ) -> Self

Installs one definition’s interface and child composition on its local graph.

Source

pub fn with_inferred_interface(self) -> Result<Self, ModuleError>

Adds inferred quantum and classical ports to a procedurally authored graph.

§Errors

Returns a typed interface error when Port directions cannot be inferred.

§Panics

Panics only if the generated Port-name sequence is internally exhausted.

Source

pub fn from_definitions(definitions: Vec<Self>) -> Result<Self, ModuleError>

Constructs a hierarchy rooted at main, preserving each definition once.

§Errors

Returns a typed declaration, geometry, dependency, or resource-limit error.

Source

pub fn from_definitions_with_limits( definitions: Vec<Self>, limits: ModuleCertificationLimits, ) -> Result<Self, ModuleError>

Constructs a hierarchy with explicit source and expansion limits.

§Errors

Returns a typed declaration, geometry, dependency, or resource-limit error.

Source

pub fn modules( &self, ) -> impl ExactSizeIterator<Item = &Self> + DoubleEndedIterator + Clone

Borrows every named definition, including this root, without copying topology.

Source

pub fn module_mut(&mut self, name: &str) -> Option<&mut Self>

Mutably borrows one named definition for edits checked by validation.

Source

pub fn root(&self) -> &Self

Returns the executable root; its local topology is stored directly here.

Source

pub fn module(&self, name: &str) -> Option<&Self>

Borrows one named definition, including the root.

Source

pub fn local_body(&self) -> &Self

Borrows this definition’s local topology and actions.

Source

pub fn clone_local_definition(&self) -> Self

Copies one definition without copying the root’s helper library.

Source

pub fn has_module_structure(&self) -> bool

Whether explicitly authored interfaces or child composition are present.

Source

pub fn flatten(&self) -> Result<Self, ModuleCertificationError>

Explicitly materializes the authored hierarchy as one flat projection.

§Errors

Returns an expansion or graph-construction error.

Source

pub fn flatten_with_limits( &self, limits: ModuleCertificationLimits, ) -> Result<Self, ModuleCertificationError>

Materializes one flat projection without resetting explicit source budgets.

§Errors

Returns a typed invalid-hierarchy, graph, or resource-limit error.

Source

pub fn validate_with_limits( &self, limits: ModuleCertificationLimits, ) -> Result<(), ModuleError>

Validates all authored definitions, interfaces, seams, and dependency cycles.

§Errors

Returns typed source, module, geometry, or resource-limit errors.

Source

pub fn extract_definition(&self, name: &str) -> Result<Self, ModuleError>

Extracts an independently compilable graph rooted at one named definition.

Includes its transitive helper definitions and renames the selected root to main, resolving any collision with a reachable original root.

§Errors

Returns a typed missing-definition, invalid-hierarchy, or resource error.

Source

pub fn extract_definition_with_limits( &self, name: &str, limits: ModuleCertificationLimits, ) -> Result<Self, ModuleError>

Extracts one definition and its dependencies with explicit source budgets.

§Errors

Returns a typed missing-definition, invalid-hierarchy, or resource error.

§Panics

Panics if validated dependency bookkeeping is internally inconsistent.

Source

pub fn certify_leaf( &self, name: &str, limits: ModuleCertificationLimits, ) -> Result<LeafModuleCertificate, ModuleCertificationError>

Certifies one definition without flattening its ZX rows.

§Errors

Returns an error if the definition is missing or cannot be certified within limits.

Source§

impl BlockGraph

Source

pub fn to_blog_text(&self) -> String

Canonical BLOG 1.0 text. Resolved imports are written inline.

Source§

impl BlockGraph

Source

pub fn summarize_root( &self, limits: ModuleCertificationLimits, ) -> Result<Arc<ModuleSummary>, ModuleCertificationError>

Builds the root’s signed quantum summary without flattening child bodies. Native concurrency defaults to the available cores capped at four.

§Errors

Returns an error if validation, certification, or a resource limit fails.

Source

pub fn summarize_root_with_jobs( &self, limits: ModuleCertificationLimits, jobs: NonZeroUsize, ) -> Result<Arc<ModuleSummary>, ModuleCertificationError>

Builds the root summary using at most jobs concurrent module workers.

Definitions at the same dependency depth run in parallel on native targets. WebAssembly remains serial.

§Errors

Returns an error if validation, certification, or a resource limit fails.

Source

pub fn direct_pipe_endpoints(&self, module: &str) -> Option<Vec<(IVec3, IVec3)>>

Physical endpoints of direct child-to-child pipes in declaration order.

§Panics

Panics if validated module geometry is internally inconsistent.

Source

pub fn direct_pipe_endpoints_by_module( &self, ) -> HashMap<String, Vec<(IVec3, IVec3)>>

Physical direct-pipe endpoints for every module, sharing geometry work.

§Panics

Panics if validated module geometry is internally inconsistent.

Source§

impl BlockGraph

Source

pub fn validate_resource_limits( &self, limits: ModuleCertificationLimits, ) -> Result<(), BlockGraphError>

Checks the whole source hierarchy’s conservative expansion budgets.

§Errors

Returns typed declaration, cycle, graph, or resource-limit errors.

Source

pub fn validate_local_resource_limits( &self, limits: ModuleCertificationLimits, ) -> Result<(), BlockGraphError>

Checks authored geometry size before cloning or enumerating occupied cells. Both branch arms count; cube footprints use their cached height in cells. This checks max_expanded_blocks and max_occupied_cells only.

§Errors

Returns a crate::StabilizerError::ResourceLimited wrapped in crate::BlockGraphError::Stabilizer when a count exceeds its limit or cannot fit in usize.

Trait Implementations§

Source§

impl Clone for BlockGraph

Source§

fn clone(&self) -> BlockGraph

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BlockGraph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for BlockGraph

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for BlockGraph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FromStr for BlockGraph

Source§

type Err = BlockGraphError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl TryFrom<&BlockGraph> for ZXGraph

Source§

type Error = ZXError

The type returned in the event of a conversion error.
Source§

fn try_from(graph: &BlockGraph) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&ZXGraph> for BlockGraph

Source§

type Error = ZXError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &ZXGraph) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T, BorrowedSelf> BitwiseMutViaBorrow<BorrowedSelf> for T
where T: BorrowMut<BorrowedSelf>, BorrowedSelf: BitwiseMut + ?Sized,

§

fn assign_index(&mut self, index: usize, to: bool)

§

fn negate_index(&mut self, index: usize)

§

fn clear_bits(&mut self)

§

fn assign_random( &mut self, bit_count: usize, random_number_generator: &mut impl RngExt, )
where BorrowedSelf: BitLength,

§

impl<Bits, Other, BorrowedSelf, BorrowedOther> BitwisePairMutViaBorrow<Other, BorrowedSelf, BorrowedOther> for Bits
where Bits: BorrowMut<BorrowedSelf> + ?Sized, Other: Borrow<BorrowedOther> + ?Sized, BorrowedSelf: Bitwise + BitwisePairMut<BorrowedOther> + ?Sized, BorrowedOther: Bitwise + ?Sized,

§

fn assign(&mut self, other: &Other)

§

fn bitxor_assign(&mut self, other: &Other)

§

fn bitand_assign(&mut self, other: &Other)

§

fn bitor_assign(&mut self, other: &Other)

§

impl<T, Other, BorrowedSelf, BorrowedOther> BitwisePairViaBorrow<Other, BorrowedSelf, BorrowedOther> for T
where T: Borrow<BorrowedSelf> + ?Sized, Other: Borrow<BorrowedOther> + ?Sized, BorrowedSelf: Bitwise + BitwisePair<BorrowedOther> + ?Sized, BorrowedOther: Bitwise + ?Sized,

§

fn dot(&self, other: &Other) -> bool

§

fn and_weight(&self, other: &Other) -> usize

§

fn or_weight(&self, other: &Other) -> usize

§

fn xor_weight(&self, other: &Other) -> usize

§

impl<T, BorrowedSelf> BitwiseViaBorrow<BorrowedSelf> for T
where T: Borrow<BorrowedSelf>, BorrowedSelf: Bitwise + ?Sized,

§

fn index(&self, index: usize) -> bool

§

fn weight(&self) -> usize

§

fn parity(&self) -> bool

§

fn is_zero(&self) -> bool

§

fn is_unit(&self, index: usize) -> bool

§

fn support<'a>(&'a self) -> impl SortedIterator
where BorrowedSelf: 'a,

§

fn max_support(&self) -> Option<usize>

§

fn min_support(&self) -> Option<usize>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> Fmt for T
where T: Display,

§

fn fg<C>(self, color: C) -> Foreground<Self>
where C: Into<Option<Color>>, Self: Display,

Give this value the specified foreground colour.
§

fn bg<C>(self, color: C) -> Background<Self>
where C: Into<Option<Color>>, Self: Display,

Give this value the specified background colour.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<'src, T> IntoMaybe<'src, T> for T
where T: 'src,

§

type Proj<U: 'src> = U

§

fn map_maybe<R>( self, _f: impl FnOnce(&'src T) -> &'src R, g: impl FnOnce(T) -> R, ) -> <T as IntoMaybe<'src, T>>::Proj<R>
where R: 'src,

§

impl<T> OrderedSeq<'_, T> for T
where T: Clone,

§

impl<T> Paint for T
where T: ?Sized,

§

fn fg(&self, value: Color) -> Painted<&T>

Returns a styled value derived from self with the foreground set to value.

This method should be used rarely. Instead, prefer to use color-specific builder methods like red() and green(), which have the same functionality but are pithier.

§Example

Set foreground color to white using fg():

use yansi::{Paint, Color};

painted.fg(Color::White);

Set foreground color to white using white().

use yansi::Paint;

painted.white();
§

fn primary(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Primary].

§Example
println!("{}", value.primary());
§

fn fixed(&self, color: u8) -> Painted<&T>

Returns self with the fg() set to [Color :: Fixed].

§Example
println!("{}", value.fixed(color));
§

fn rgb(&self, r: u8, g: u8, b: u8) -> Painted<&T>

Returns self with the fg() set to [Color :: Rgb].

§Example
println!("{}", value.rgb(r, g, b));
§

fn black(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Black].

§Example
println!("{}", value.black());
§

fn red(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Red].

§Example
println!("{}", value.red());
§

fn green(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Green].

§Example
println!("{}", value.green());
§

fn yellow(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Yellow].

§Example
println!("{}", value.yellow());
§

fn blue(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Blue].

§Example
println!("{}", value.blue());
§

fn magenta(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Magenta].

§Example
println!("{}", value.magenta());
§

fn cyan(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Cyan].

§Example
println!("{}", value.cyan());
§

fn white(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: White].

§Example
println!("{}", value.white());
§

fn bright_black(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightBlack].

§Example
println!("{}", value.bright_black());
§

fn bright_red(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightRed].

§Example
println!("{}", value.bright_red());
§

fn bright_green(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightGreen].

§Example
println!("{}", value.bright_green());
§

fn bright_yellow(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightYellow].

§Example
println!("{}", value.bright_yellow());
§

fn bright_blue(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightBlue].

§Example
println!("{}", value.bright_blue());
§

fn bright_magenta(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightMagenta].

§Example
println!("{}", value.bright_magenta());
§

fn bright_cyan(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightCyan].

§Example
println!("{}", value.bright_cyan());
§

fn bright_white(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightWhite].

§Example
println!("{}", value.bright_white());
§

fn bg(&self, value: Color) -> Painted<&T>

Returns a styled value derived from self with the background set to value.

This method should be used rarely. Instead, prefer to use color-specific builder methods like on_red() and on_green(), which have the same functionality but are pithier.

§Example

Set background color to red using fg():

use yansi::{Paint, Color};

painted.bg(Color::Red);

Set background color to red using on_red().

use yansi::Paint;

painted.on_red();
§

fn on_primary(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Primary].

§Example
println!("{}", value.on_primary());
§

fn on_fixed(&self, color: u8) -> Painted<&T>

Returns self with the bg() set to [Color :: Fixed].

§Example
println!("{}", value.on_fixed(color));
§

fn on_rgb(&self, r: u8, g: u8, b: u8) -> Painted<&T>

Returns self with the bg() set to [Color :: Rgb].

§Example
println!("{}", value.on_rgb(r, g, b));
§

fn on_black(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Black].

§Example
println!("{}", value.on_black());
§

fn on_red(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Red].

§Example
println!("{}", value.on_red());
§

fn on_green(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Green].

§Example
println!("{}", value.on_green());
§

fn on_yellow(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Yellow].

§Example
println!("{}", value.on_yellow());
§

fn on_blue(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Blue].

§Example
println!("{}", value.on_blue());
§

fn on_magenta(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Magenta].

§Example
println!("{}", value.on_magenta());
§

fn on_cyan(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Cyan].

§Example
println!("{}", value.on_cyan());
§

fn on_white(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: White].

§Example
println!("{}", value.on_white());
§

fn on_bright_black(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightBlack].

§Example
println!("{}", value.on_bright_black());
§

fn on_bright_red(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightRed].

§Example
println!("{}", value.on_bright_red());
§

fn on_bright_green(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightGreen].

§Example
println!("{}", value.on_bright_green());
§

fn on_bright_yellow(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightYellow].

§Example
println!("{}", value.on_bright_yellow());
§

fn on_bright_blue(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightBlue].

§Example
println!("{}", value.on_bright_blue());
§

fn on_bright_magenta(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightMagenta].

§Example
println!("{}", value.on_bright_magenta());
§

fn on_bright_cyan(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightCyan].

§Example
println!("{}", value.on_bright_cyan());
§

fn on_bright_white(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightWhite].

§Example
println!("{}", value.on_bright_white());
§

fn attr(&self, value: Attribute) -> Painted<&T>

Enables the styling [Attribute] value.

This method should be used rarely. Instead, prefer to use attribute-specific builder methods like bold() and underline(), which have the same functionality but are pithier.

§Example

Make text bold using attr():

use yansi::{Paint, Attribute};

painted.attr(Attribute::Bold);

Make text bold using using bold().

use yansi::Paint;

painted.bold();
§

fn bold(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Bold].

§Example
println!("{}", value.bold());
§

fn dim(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Dim].

§Example
println!("{}", value.dim());
§

fn italic(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Italic].

§Example
println!("{}", value.italic());
§

fn underline(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Underline].

§Example
println!("{}", value.underline());

Returns self with the attr() set to [Attribute :: Blink].

§Example
println!("{}", value.blink());

Returns self with the attr() set to [Attribute :: RapidBlink].

§Example
println!("{}", value.rapid_blink());
§

fn invert(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Invert].

§Example
println!("{}", value.invert());
§

fn conceal(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Conceal].

§Example
println!("{}", value.conceal());
§

fn strike(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Strike].

§Example
println!("{}", value.strike());
§

fn quirk(&self, value: Quirk) -> Painted<&T>

Enables the yansi [Quirk] value.

This method should be used rarely. Instead, prefer to use quirk-specific builder methods like mask() and wrap(), which have the same functionality but are pithier.

§Example

Enable wrapping using .quirk():

use yansi::{Paint, Quirk};

painted.quirk(Quirk::Wrap);

Enable wrapping using wrap().

use yansi::Paint;

painted.wrap();
§

fn mask(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Mask].

§Example
println!("{}", value.mask());
§

fn wrap(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Wrap].

§Example
println!("{}", value.wrap());
§

fn linger(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Linger].

§Example
println!("{}", value.linger());
§

fn clear(&self) -> Painted<&T>

👎Deprecated since 1.0.1:

renamed to resetting() due to conflicts with Vec::clear(). The clear() method will be removed in a future release.

Returns self with the quirk() set to [Quirk :: Clear].

§Example
println!("{}", value.clear());
§

fn resetting(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Resetting].

§Example
println!("{}", value.resetting());
§

fn bright(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Bright].

§Example
println!("{}", value.bright());
§

fn on_bright(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: OnBright].

§Example
println!("{}", value.on_bright());
§

fn whenever(&self, value: Condition) -> Painted<&T>

Conditionally enable styling based on whether the [Condition] value applies. Replaces any previous condition.

See the crate level docs for more details.

§Example

Enable styling painted only when both stdout and stderr are TTYs:

use yansi::{Paint, Condition};

painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);
§

fn new(self) -> Painted<Self>
where Self: Sized,

Create a new [Painted] with a default [Style]. Read more
§

fn paint<S>(&self, style: S) -> Painted<&Self>
where S: Into<Style>,

Apply a style wholesale to self. Any previous style is replaced. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<'p, T> Seq<'p, T> for T
where T: Clone,

§

type Item<'a> = &'a T where T: 'a

The item yielded by the iterator.
§

type Iter<'a> = Once<&'a T> where T: 'a

An iterator over the items within this container, by reference.
§

fn seq_iter(&self) -> <T as Seq<'p, T>>::Iter<'_>

Iterate over the elements of the container.
§

fn contains(&self, val: &T) -> bool
where T: PartialEq,

Check whether an item is contained within this sequence.
§

fn to_maybe_ref<'b>(item: <T as Seq<'p, T>>::Item<'b>) -> Maybe<T, &'p T>
where 'p: 'b,

Convert an item of the sequence into a [MaybeRef].
§

impl<T, S> SpanWrap<S> for T
where S: WrappingSpan<T>,

§

fn with_span(self, span: S) -> <S as WrappingSpan<Self>>::Spanned

Invokes [WrappingSpan::make_wrapped] to wrap an AST node in a span.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V