Context

Struct Context 

Source
pub struct Context { /* private fields */ }
Expand description

A Context holds a set of deduplicated constants, variables, and operations.

It should be used like an arena allocator: it grows over time, then frees all of its contents when dropped. There is no reference counting within the context.

Items in the context are accessed with Node keys, which are simple handles into an internal map. Inside the context, operations are represented with the Op type.

Implementations§

Source§

impl Context

Source

pub fn new() -> Self

Build a new empty context

Source

pub fn clear(&mut self)

Clears the context

All Node handles from this context are invalidated.

let mut ctx = Context::new();
let x = ctx.x();
ctx.clear();
assert!(ctx.eval_xyz(x, 1.0, 0.0, 0.0).is_err());
Source

pub fn len(&self) -> usize

Returns the number of Op nodes in the context

let mut ctx = Context::new();
let x = ctx.x();
assert_eq!(ctx.len(), 1);
let y = ctx.y();
assert_eq!(ctx.len(), 2);
ctx.clear();
assert_eq!(ctx.len(), 0);
Source

pub fn is_empty(&self) -> bool

Checks whether the context is empty

Source

pub fn get_const(&self, n: Node) -> Result<f64, Error>

Looks up the constant associated with the given node.

If the node is invalid for this tree, returns an error; if the node is not a constant, returns Ok(None).

Source

pub fn get_var(&self, n: Node) -> Result<Var, Error>

Looks up the Var associated with the given node.

If the node is invalid for this tree or not an Op::Input, returns an error.

Source

pub fn x(&mut self) -> Node

Constructs or finds a Var::X node

let mut ctx = Context::new();
let x = ctx.x();
let v = ctx.eval_xyz(x, 1.0, 0.0, 0.0).unwrap();
assert_eq!(v, 1.0);
Source

pub fn y(&mut self) -> Node

Constructs or finds a Var::Y node

Source

pub fn z(&mut self) -> Node

Constructs or finds a Var::Z node

Source

pub fn var(&mut self, v: Var) -> Node

Constructs or finds a variable input node

To make an anonymous variable, call this function with Var::new():

let mut ctx = Context::new();
let v1 = ctx.var(Var::new());
let v2 = ctx.var(Var::new());
assert_ne!(v1, v2);

let mut vars = HashMap::new();
vars.insert(ctx.get_var(v1).unwrap(), 3.0);
assert_eq!(ctx.eval(v1, &vars).unwrap(), 3.0);
assert!(ctx.eval(v2, &vars).is_err()); // v2 isn't in the map
Source

pub fn axes(&mut self) -> [Node; 3]

Returns a 3-element array of X, Y, Z nodes

Source

pub fn constant(&mut self, f: f64) -> Node

Returns a node representing the given constant value.

let v = ctx.constant(3.0);
assert_eq!(ctx.eval_xyz(v, 0.0, 0.0, 0.0).unwrap(), 3.0);
Source

pub fn add<A: IntoNode, B: IntoNode>( &mut self, a: A, b: B, ) -> Result<Node, Error>

Builds an addition node

let x = ctx.x();
let op = ctx.add(x, 1.0).unwrap();
let v = ctx.eval_xyz(op, 1.0, 0.0, 0.0).unwrap();
assert_eq!(v, 2.0);
Source

pub fn mul<A: IntoNode, B: IntoNode>( &mut self, a: A, b: B, ) -> Result<Node, Error>

Builds an multiplication node

let x = ctx.x();
let op = ctx.mul(x, 5.0).unwrap();
let v = ctx.eval_xyz(op, 2.0, 0.0, 0.0).unwrap();
assert_eq!(v, 10.0);
Source

pub fn min<A: IntoNode, B: IntoNode>( &mut self, a: A, b: B, ) -> Result<Node, Error>

Builds an min node

let x = ctx.x();
let op = ctx.min(x, 5.0).unwrap();
let v = ctx.eval_xyz(op, 2.0, 0.0, 0.0).unwrap();
assert_eq!(v, 2.0);
Source

pub fn max<A: IntoNode, B: IntoNode>( &mut self, a: A, b: B, ) -> Result<Node, Error>

Builds an max node

let x = ctx.x();
let op = ctx.max(x, 5.0).unwrap();
let v = ctx.eval_xyz(op, 2.0, 0.0, 0.0).unwrap();
assert_eq!(v, 5.0);
Source

pub fn and<A: IntoNode, B: IntoNode>( &mut self, a: A, b: B, ) -> Result<Node, Error>

Builds an and node

If both arguments are non-zero, returns the right-hand argument. Otherwise, returns zero.

This node can be simplified using a tracing evaluator:

  • If the left-hand argument is zero, simplify to just that argument
  • If the left-hand argument is non-zero, simplify to the other argument
let x = ctx.x();
let y = ctx.y();
let op = ctx.and(x, y).unwrap();
let v = ctx.eval_xyz(op, 1.0, 0.0, 0.0).unwrap();
assert_eq!(v, 0.0);
let v = ctx.eval_xyz(op, 1.0, 1.0, 0.0).unwrap();
assert_eq!(v, 1.0);
let v = ctx.eval_xyz(op, 1.0, 2.0, 0.0).unwrap();
assert_eq!(v, 2.0);
Source

pub fn or<A: IntoNode, B: IntoNode>( &mut self, a: A, b: B, ) -> Result<Node, Error>

Builds an or node

If the left-hand argument is non-zero, it is returned. Otherwise, the right-hand argument is returned.

This node can be simplified using a tracing evaluator.

let x = ctx.x();
let y = ctx.y();
let op = ctx.or(x, y).unwrap();
let v = ctx.eval_xyz(op, 1.0, 0.0, 0.0).unwrap();
assert_eq!(v, 1.0);
let v = ctx.eval_xyz(op, 0.0, 0.0, 0.0).unwrap();
assert_eq!(v, 0.0);
let v = ctx.eval_xyz(op, 0.0, 3.0, 0.0).unwrap();
assert_eq!(v, 3.0);
Source

pub fn not<A: IntoNode>(&mut self, a: A) -> Result<Node, Error>

Builds a logical negation node

The output is 1 if the argument is 0, and 0 otherwise.

Source

pub fn neg<A: IntoNode>(&mut self, a: A) -> Result<Node, Error>

Builds a unary negation node

let x = ctx.x();
let op = ctx.neg(x).unwrap();
let v = ctx.eval_xyz(op, 2.0, 0.0, 0.0).unwrap();
assert_eq!(v, -2.0);
Source

pub fn recip<A: IntoNode>(&mut self, a: A) -> Result<Node, Error>

Builds a reciprocal node

let x = ctx.x();
let op = ctx.recip(x).unwrap();
let v = ctx.eval_xyz(op, 2.0, 0.0, 0.0).unwrap();
assert_eq!(v, 0.5);
Source

pub fn abs<A: IntoNode>(&mut self, a: A) -> Result<Node, Error>

Builds a node which calculates the absolute value of its input

let x = ctx.x();
let op = ctx.abs(x).unwrap();
let v = ctx.eval_xyz(op, 2.0, 0.0, 0.0).unwrap();
assert_eq!(v, 2.0);
let v = ctx.eval_xyz(op, -2.0, 0.0, 0.0).unwrap();
assert_eq!(v, 2.0);
Source

pub fn sqrt<A: IntoNode>(&mut self, a: A) -> Result<Node, Error>

Builds a node which calculates the square root of its input

let x = ctx.x();
let op = ctx.sqrt(x).unwrap();
let v = ctx.eval_xyz(op, 4.0, 0.0, 0.0).unwrap();
assert_eq!(v, 2.0);
Source

pub fn sin<A: IntoNode>(&mut self, a: A) -> Result<Node, Error>

Builds a node which calculates the sine of its input (in radians)

let x = ctx.x();
let op = ctx.sin(x).unwrap();
let v = ctx.eval_xyz(op, std::f64::consts::PI / 2.0, 0.0, 0.0).unwrap();
assert_eq!(v, 1.0);
Source

pub fn cos<A: IntoNode>(&mut self, a: A) -> Result<Node, Error>

Builds a node which calculates the cosine of its input (in radians)

Source

pub fn tan<A: IntoNode>(&mut self, a: A) -> Result<Node, Error>

Builds a node which calculates the tangent of its input (in radians)

Source

pub fn asin<A: IntoNode>(&mut self, a: A) -> Result<Node, Error>

Builds a node which calculates the arcsine of its input (in radians)

Source

pub fn acos<A: IntoNode>(&mut self, a: A) -> Result<Node, Error>

Builds a node which calculates the arccosine of its input (in radians)

Source

pub fn atan<A: IntoNode>(&mut self, a: A) -> Result<Node, Error>

Builds a node which calculates the arctangent of its input (in radians)

Source

pub fn exp<A: IntoNode>(&mut self, a: A) -> Result<Node, Error>

Builds a node which calculates the exponent of its input

Source

pub fn ln<A: IntoNode>(&mut self, a: A) -> Result<Node, Error>

Builds a node which calculates the natural log of its input

Source

pub fn square<A: IntoNode>(&mut self, a: A) -> Result<Node, Error>

Builds a node which squares its input

let x = ctx.x();
let op = ctx.square(x).unwrap();
let v = ctx.eval_xyz(op, 2.0, 0.0, 0.0).unwrap();
assert_eq!(v, 4.0);
Source

pub fn floor<A: IntoNode>(&mut self, a: A) -> Result<Node, Error>

Builds a node which takes the floor of its input

let x = ctx.x();
let op = ctx.floor(x).unwrap();
let v = ctx.eval_xyz(op, 1.2, 0.0, 0.0).unwrap();
assert_eq!(v, 1.0);
Source

pub fn ceil<A: IntoNode>(&mut self, a: A) -> Result<Node, Error>

Builds a node which takes the ceiling of its input

let x = ctx.x();
let op = ctx.ceil(x).unwrap();
let v = ctx.eval_xyz(op, 1.2, 0.0, 0.0).unwrap();
assert_eq!(v, 2.0);
Source

pub fn round<A: IntoNode>(&mut self, a: A) -> Result<Node, Error>

Builds a node which rounds its input to the nearest integer

let x = ctx.x();
let op = ctx.round(x).unwrap();
let v = ctx.eval_xyz(op, 1.2, 0.0, 0.0).unwrap();
assert_eq!(v, 1.0);
let v = ctx.eval_xyz(op, 1.6, 0.0, 0.0).unwrap();
assert_eq!(v, 2.0);
let v = ctx.eval_xyz(op, 1.5, 0.0, 0.0).unwrap();
assert_eq!(v, 2.0); // rounds away from 0.0 if ambiguous
Source

pub fn sub<A: IntoNode, B: IntoNode>( &mut self, a: A, b: B, ) -> Result<Node, Error>

Builds a node which performs subtraction.

let x = ctx.x();
let y = ctx.y();
let op = ctx.sub(x, y).unwrap();
let v = ctx.eval_xyz(op, 3.0, 2.0, 0.0).unwrap();
assert_eq!(v, 1.0);
Source

pub fn div<A: IntoNode, B: IntoNode>( &mut self, a: A, b: B, ) -> Result<Node, Error>

Builds a node which performs division.

let x = ctx.x();
let y = ctx.y();
let op = ctx.div(x, y).unwrap();
let v = ctx.eval_xyz(op, 3.0, 2.0, 0.0).unwrap();
assert_eq!(v, 1.5);
Source

pub fn atan2<A: IntoNode, B: IntoNode>( &mut self, y: A, x: B, ) -> Result<Node, Error>

Builds a node which computes atan2(y, x)

let x = ctx.x();
let y = ctx.y();
let op = ctx.atan2(y, x).unwrap();
let v = ctx.eval_xyz(op, 0.0, 1.0, 0.0).unwrap();
assert_eq!(v, std::f64::consts::FRAC_PI_2);
Source

pub fn compare<A: IntoNode, B: IntoNode>( &mut self, a: A, b: B, ) -> Result<Node, Error>

Builds a node that compares two values

The result is -1 if a < b, +1 if a > b, 0 if a == b, and NaN if either side is NaN.

let x = ctx.x();
let op = ctx.compare(x, 1.0).unwrap();
let v = ctx.eval_xyz(op, 0.0, 0.0, 0.0).unwrap();
assert_eq!(v, -1.0);
let v = ctx.eval_xyz(op, 2.0, 0.0, 0.0).unwrap();
assert_eq!(v, 1.0);
let v = ctx.eval_xyz(op, 1.0, 0.0, 0.0).unwrap();
assert_eq!(v, 0.0);
Source

pub fn less_than<A: IntoNode, B: IntoNode>( &mut self, lhs: A, rhs: B, ) -> Result<Node, Error>

Builds a node that is 1 if lhs < rhs and 0 otherwise

let x = ctx.x();
let y = ctx.y();
let op = ctx.less_than(x, y).unwrap();
let v = ctx.eval_xyz(op, 0.0, 1.0, 0.0).unwrap();
assert_eq!(v, 1.0);
let v = ctx.eval_xyz(op, 1.0, 1.0, 0.0).unwrap();
assert_eq!(v, 0.0);
let v = ctx.eval_xyz(op, 2.0, 1.0, 0.0).unwrap();
assert_eq!(v, 0.0);
Source

pub fn less_than_or_equal<A: IntoNode, B: IntoNode>( &mut self, lhs: A, rhs: B, ) -> Result<Node, Error>

Builds a node that is 1 if lhs <= rhs and 0 otherwise

let x = ctx.x();
let y = ctx.y();
let op = ctx.less_than_or_equal(x, y).unwrap();
let v = ctx.eval_xyz(op, 0.0, 1.0, 0.0).unwrap();
assert_eq!(v, 1.0);
let v = ctx.eval_xyz(op, 1.0, 1.0, 0.0).unwrap();
assert_eq!(v, 1.0);
let v = ctx.eval_xyz(op, 2.0, 1.0, 0.0).unwrap();
assert_eq!(v, 0.0);
Source

pub fn modulo<A: IntoNode, B: IntoNode>( &mut self, a: A, b: B, ) -> Result<Node, Error>

Builds a node that takes the modulo (least non-negative remainder)

Source

pub fn if_nonzero_else<Condition: IntoNode, A: IntoNode, B: IntoNode>( &mut self, condition: Condition, a: A, b: B, ) -> Result<Node, Error>

Builds a node that returns the first node if the condition is not equal to zero, else returns the other node

The result is a if condition != 0, else the result is b.

let x = ctx.x();
let y = ctx.y();
let z = ctx.z();

let if_else = ctx.if_nonzero_else(x, y, z).unwrap();

assert_eq!(ctx.eval_xyz(if_else, 0.0, 2.0, 3.0).unwrap(), 3.0);
assert_eq!(ctx.eval_xyz(if_else, 1.0, 2.0, 3.0).unwrap(), 2.0);
assert_eq!(ctx.eval_xyz(if_else, 0.0, f64::NAN, 3.0).unwrap(), 3.0);
assert_eq!(ctx.eval_xyz(if_else, 1.0, 2.0, f64::NAN).unwrap(), 2.0);
Source

pub fn eval_xyz(&self, root: Node, x: f64, y: f64, z: f64) -> Result<f64, Error>

Evaluates the given node with the provided values for X, Y, and Z.

This is extremely inefficient; consider converting the node into a Shape and using its evaluators instead.

let x = ctx.x();
let y = ctx.y();
let z = ctx.z();
let op = ctx.mul(x, y).unwrap();
let op = ctx.div(op, z).unwrap();
let v = ctx.eval_xyz(op, 3.0, 5.0, 2.0).unwrap();
assert_eq!(v, 7.5); // (3.0 * 5.0) / 2.0
Source

pub fn eval(&self, root: Node, vars: &HashMap<Var, f64>) -> Result<f64, Error>

Evaluates the given node with a generic set of variables

This is extremely inefficient; consider converting the node into a Shape and using its evaluators instead.

Source

pub fn from_text<R: Read>(r: R) -> Result<(Self, Node), Error>

Parses a flat text representation of a math tree. For example, the circle (- (+ (square x) (square y)) 1) can be parsed from

let txt = "
# This is a comment!
0x600000b90000 var-x
0x600000b900a0 square 0x600000b90000
0x600000b90050 var-y
0x600000b900f0 square 0x600000b90050
0x600000b90140 add 0x600000b900a0 0x600000b900f0
0x600000b90190 sqrt 0x600000b90140
0x600000b901e0 const 1
";
let (ctx, _node) = Context::from_text(&mut txt.as_bytes()).unwrap();
assert_eq!(ctx.len(), 7);

This representation is loosely defined and only intended for use in quick experiments.

Source

pub fn dot(&self) -> String

Converts the entire context into a GraphViz drawing

Source

pub fn get_op(&self, node: Node) -> Option<&Op>

Looks up an operation by Node handle

Source

pub fn import(&mut self, tree: &Tree) -> Node

Imports the given tree, deduplicating and returning the root

Source

pub fn export(&self, n: Node) -> Result<Tree, Error>

Converts from a context-specific node into a standalone Tree

Source

pub fn deriv(&mut self, n: Node, v: Var) -> Result<Node, Error>

Takes the symbolic derivative of a node with respect to a variable

Trait Implementations§

Source§

impl Debug for Context

Source§

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

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

impl Default for Context

Source§

fn default() -> Context

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

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
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
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
Source§

impl<D> OwoColorize for D

Source§

fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>
where C: Color,

Set the foreground color generically Read more
Source§

fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>
where C: Color,

Set the background color generically. Read more
Source§

fn black(&self) -> FgColorDisplay<'_, Black, Self>

Change the foreground color to black
Source§

fn on_black(&self) -> BgColorDisplay<'_, Black, Self>

Change the background color to black
Source§

fn red(&self) -> FgColorDisplay<'_, Red, Self>

Change the foreground color to red
Source§

fn on_red(&self) -> BgColorDisplay<'_, Red, Self>

Change the background color to red
Source§

fn green(&self) -> FgColorDisplay<'_, Green, Self>

Change the foreground color to green
Source§

fn on_green(&self) -> BgColorDisplay<'_, Green, Self>

Change the background color to green
Source§

fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>

Change the foreground color to yellow
Source§

fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>

Change the background color to yellow
Source§

fn blue(&self) -> FgColorDisplay<'_, Blue, Self>

Change the foreground color to blue
Source§

fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>

Change the background color to blue
Source§

fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to magenta
Source§

fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to magenta
Source§

fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to purple
Source§

fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to purple
Source§

fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>

Change the foreground color to cyan
Source§

fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>

Change the background color to cyan
Source§

fn white(&self) -> FgColorDisplay<'_, White, Self>

Change the foreground color to white
Source§

fn on_white(&self) -> BgColorDisplay<'_, White, Self>

Change the background color to white
Source§

fn default_color(&self) -> FgColorDisplay<'_, Default, Self>

Change the foreground color to the terminal default
Source§

fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>

Change the background color to the terminal default
Source§

fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>

Change the foreground color to bright black
Source§

fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>

Change the background color to bright black
Source§

fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>

Change the foreground color to bright red
Source§

fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>

Change the background color to bright red
Source§

fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>

Change the foreground color to bright green
Source§

fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>

Change the background color to bright green
Source§

fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>

Change the foreground color to bright yellow
Source§

fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>

Change the background color to bright yellow
Source§

fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>

Change the foreground color to bright blue
Source§

fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>

Change the background color to bright blue
Source§

fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright magenta
Source§

fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright magenta
Source§

fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright purple
Source§

fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright purple
Source§

fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>

Change the foreground color to bright cyan
Source§

fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>

Change the background color to bright cyan
Source§

fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>

Change the foreground color to bright white
Source§

fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>

Change the background color to bright white
Source§

fn bold(&self) -> BoldDisplay<'_, Self>

Make the text bold
Source§

fn dimmed(&self) -> DimDisplay<'_, Self>

Make the text dim
Source§

fn italic(&self) -> ItalicDisplay<'_, Self>

Make the text italicized
Source§

fn underline(&self) -> UnderlineDisplay<'_, Self>

Make the text underlined
Make the text blink
Make the text blink (but fast!)
Source§

fn reversed(&self) -> ReversedDisplay<'_, Self>

Swap the foreground and background colors
Source§

fn hidden(&self) -> HiddenDisplay<'_, Self>

Hide the text
Source§

fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>

Cross out the text
Source§

fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either OwoColorize::fg or a color-specific method, such as OwoColorize::green, Read more
Source§

fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either OwoColorize::bg or a color-specific method, such as OwoColorize::on_yellow, Read more
Source§

fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the foreground color to a specific RGB value.
Source§

fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the background color to a specific RGB value.
Source§

fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>

Sets the foreground color to an RGB value.
Source§

fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>

Sets the background color to an RGB value.
Source§

fn style(&self, style: Style) -> Styled<&Self>

Apply a runtime-determined style
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.
Source§

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

Source§

fn vzip(self) -> V