pub struct Block { /* private fields */ }Expand description
A single block placed at a 3D lattice position in a BlockGraph.
§Examples
use bloq_graph::{Block, BlockKind, CubeKind};
use glam::IVec3;
let block = Block::new(IVec3::ZERO, BlockKind::Cube(CubeKind::ZXZ)).with_tag("entry")?;
assert_eq!(block.pos(), IVec3::ZERO);
assert_eq!(block.kind(), BlockKind::Cube(CubeKind::ZXZ));
assert_eq!(block.tag(), Some("entry"));Implementations§
Source§impl Block
impl Block
Sourcepub fn new(pos: impl Into<IVec3>, kind: impl Into<BlockKind>) -> Self
pub fn new(pos: impl Into<IVec3>, kind: impl Into<BlockKind>) -> Self
Create an untagged block.
Sourcepub fn height(&self) -> CubeHeight
pub fn height(&self) -> CubeHeight
Returns the symbolic cube height, always CubeHeight::DEFAULT for
non-cube kinds.
Sourcepub fn height_cells(&self) -> u32
pub fn height_cells(&self) -> u32
Returns how many lattice cells the block occupies along the time axis:
the footprint half of height, driving positioning,
occupancy, connectivity and visualization. Not the compiled round count
(CubeHeight::rounds) — height=d/2 occupies
one cell but compiles to ceil(d/2) rounds.
Sourcepub fn with_height(self, height: CubeHeight) -> Result<Self, BlockError>
pub fn with_height(self, height: CubeHeight) -> Result<Self, BlockError>
Returns the block with its cube height set to height.
§Errors
Returns a BlockError if the block is not a cube, or if the
resulting footprint leaves the coordinate range.
Sourcepub fn port_color(&self) -> Option<RGBA>
pub fn port_color(&self) -> Option<RGBA>
Returns this Port’s display color, or None for non-Ports.
Sourcepub fn with_port_color(self, rgb: [u8; 3]) -> Result<Self, BlockError>
pub fn with_port_color(self, rgb: [u8; 3]) -> Result<Self, BlockError>
Sets this Port’s RGB display color. Alpha stays fixed and default gray is omitted from serialization.
§Errors
Returns BlockError::PortColorOnNonPort for a non-Port block.
Sourcepub fn port_role(&self) -> Option<PortRole>
pub fn port_role(&self) -> Option<PortRole>
Returns this Port’s assigned direction, or None for non-Ports.
Sourcepub fn with_port_role(self, role: PortRole) -> Result<Self, BlockError>
pub fn with_port_role(self, role: PortRole) -> Result<Self, BlockError>
Assigns this Port’s role.
§Errors
Returns BlockError::PortRoleOnNonPort if this is not a Port block.
Sourcepub fn with_tag(self, tag: impl Into<String>) -> Result<Self, BlockGraphError>
pub fn with_tag(self, tag: impl Into<String>) -> Result<Self, BlockGraphError>
Returns the block tagged with tag. An empty tag clears the tag.
§Errors
Returns BlockGraphError::InvalidTag unless tag is empty or
satisfies is_valid_tag; an invalid tag would not survive a
to_blog_text round-trip.
Sourcepub fn with_shift(&self, offset: impl Into<IVec3>) -> Self
pub fn with_shift(&self, offset: impl Into<IVec3>) -> Self
Returns a copy of the block translated by offset.
§Panics
Panics if the translated footprint exceeds the coordinate range. Use
try_with_shift for untrusted offsets.
Sourcepub fn try_with_shift(
&self,
offset: impl Into<IVec3>,
) -> Result<Self, BlockGraphError>
pub fn try_with_shift( &self, offset: impl Into<IVec3>, ) -> Result<Self, BlockGraphError>
Returns a copy of the block translated by offset.
§Errors
Returns BlockGraphError::CoordinateOverflow if any translated
footprint cell exceeds the coordinate range.
Sourcepub fn reserved_offsets(&self) -> SmallVec<[IVec3; 2]>
pub fn reserved_offsets(&self) -> SmallVec<[IVec3; 2]>
Returns every cell the block occupies, as offsets from its position.
A cube reserves one cell per height cell; other kinds defer to
BlockKind::reserved_offsets.
Sourcepub fn connectable_offsets(&self) -> SmallVec<[IVec3; 2]>
pub fn connectable_offsets(&self) -> SmallVec<[IVec3; 2]>
Returns the cells that can host pipe connections, as offsets from the block position.
A multi-cell cube exposes its bottom and top cells; other kinds defer to
BlockKind::connectable_offsets.
Sourcepub fn occupies_layer(&self, z: i32) -> bool
pub fn occupies_layer(&self, z: i32) -> bool
Returns whether the block reserves any cell in time layer z.
Sourcepub fn bases_at_endpoint(&self, endpoint: IVec3) -> Option<[Basis; 3]>
pub fn bases_at_endpoint(&self, endpoint: IVec3) -> Option<[Basis; 3]>
Returns the boundary bases exposed at the connectable endpoint, or
None if the block exposes no endpoint there.
Sourcepub fn endpoint_for_direction(&self, dir: Direction) -> IVec3
pub fn endpoint_for_direction(&self, dir: Direction) -> IVec3
Returns the exposed connectable endpoint facing dir.
Multi-span blocks can reserve interior cells that are not valid external
endpoints; for example a multi-cell cube resolves +Z to its top cell.
Trait Implementations§
impl Eq for Block
Source§impl Ord for Block
impl Ord for Block
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Block
impl PartialOrd for Block
impl StructuralPartialEq for Block
Auto Trait Implementations§
impl Freeze for Block
impl RefUnwindSafe for Block
impl Send for Block
impl Sync for Block
impl Unpin for Block
impl UnsafeUnpin for Block
impl UnwindSafe for Block
Blanket Implementations§
§impl<T, BorrowedSelf> BitwiseMutViaBorrow<BorrowedSelf> for T
impl<T, BorrowedSelf> BitwiseMutViaBorrow<BorrowedSelf> for T
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
impl<Bits, Other, BorrowedSelf, BorrowedOther> BitwisePairMutViaBorrow<Other, BorrowedSelf, BorrowedOther> for Bits
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
impl<T, Other, BorrowedSelf, BorrowedOther> BitwisePairViaBorrow<Other, BorrowedSelf, BorrowedOther> for T
§impl<T, BorrowedSelf> BitwiseViaBorrow<BorrowedSelf> for T
impl<T, BorrowedSelf> BitwiseViaBorrow<BorrowedSelf> for T
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 SortedIteratorwhere
BorrowedSelf: 'a,
fn max_support(&self) -> Option<usize>
fn min_support(&self) -> Option<usize>
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 Twhere
T: 'src,
impl<'src, T> IntoMaybe<'src, T> for Twhere
T: 'src,
impl<T> OrderedSeq<'_, T> for Twhere
T: Clone,
§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
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 bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
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>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
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 rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
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 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.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
§fn whenever(&self, value: Condition) -> Painted<&T>
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);§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<'p, T> Seq<'p, T> for Twhere
T: Clone,
impl<'p, T> Seq<'p, T> for Twhere
T: Clone,
§type Iter<'a> = Once<&'a T>
where
T: 'a
type Iter<'a> = Once<&'a T> where T: 'a
§fn contains(&self, val: &T) -> boolwhere
T: PartialEq,
fn contains(&self, val: &T) -> boolwhere
T: PartialEq,
§fn to_maybe_ref<'b>(item: <T as Seq<'p, T>>::Item<'b>) -> Maybe<T, &'p T>where
'p: 'b,
fn to_maybe_ref<'b>(item: <T as Seq<'p, T>>::Item<'b>) -> Maybe<T, &'p T>where
'p: 'b,
MaybeRef].