Skip to main content

MatrixConfigBuilder

Struct MatrixConfigBuilder 

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

Fluent builder for MatrixConfig.

Construct via MatrixConfig::builder or MatrixConfigBuilder::new. Setters take and return self so they can be chained. Call build to validate and produce a MatrixConfig, or receive a MatrixError describing which invariant failed.

§Example

use matrix_rain::{CharSet, MatrixConfig, Theme};

let cfg = MatrixConfig::builder()
    .fps(60)
    .density(0.8)
    .charset(CharSet::Hex)
    .theme(Theme::Cyan)
    .build()
    .unwrap();

Implementations§

Source§

impl MatrixConfigBuilder

Source

pub fn new() -> Self

Returns a new builder seeded with MatrixConfig::default.

Source

pub fn charset(self, charset: CharSet) -> Self

Set the glyph source. See CharSet.

Source

pub fn theme(self, theme: Theme) -> Self

Set the color theme. See Theme.

Source

pub fn fps(self, fps: u16) -> Self

Set frames per second. Must be >= 1; build rejects 0.

Source

pub fn speed(self, speed: f32) -> Self

Set the global speed multiplier. Must be finite and > 0.0.

Source

pub fn density(self, density: f32) -> Self

Set the column-activity density. Must be finite and in [0.0, 1.0].

Source

pub fn min_trail(self, min_trail: u16) -> Self

Set the minimum trail length. Must be >= 1 and <= max_trail.

Source

pub fn max_trail(self, max_trail: u16) -> Self

Set the maximum trail length. Must be <= MAX_TRAIL_LIMIT.

Source

pub fn mutation_rate(self, mutation_rate: f32) -> Self

Set the per-cell glyph reroll probability per tick. Finite, [0.0, 1.0].

Source

pub fn bold_head(self, bold_head: bool) -> Self

Apply Modifier::BOLD to the head cell when true.

Source

pub fn head_white(self, head_white: bool) -> Self

Use ColorRamp.head for the head cell when true, ColorRamp.bright when false.

Source

pub fn glitch(self, glitch: f32) -> Self

Set the per-cell glitch (color flicker) probability per tick. Finite, [0.0, 1.0]. See MatrixConfig::glitch.

Source

pub fn background(self, background: Option<Color>) -> Self

Set the background color. None for transparent (skip cells in the fade zone); Some(c) for a known compositing background.

Source

pub fn build(self) -> Result<MatrixConfig, MatrixError>

Validate the configured fields and return a MatrixConfig.

§Errors

Returns MatrixError::InvalidConfig if any of the following fails (checked in order):

  • fps >= 1
  • speed is finite and > 0
  • density is finite and in [0.0, 1.0]
  • min_trail >= 1
  • min_trail <= max_trail
  • max_trail <= MAX_TRAIL_LIMIT
  • mutation_rate is finite and in [0.0, 1.0]
  • glitch is finite and in [0.0, 1.0]

Returns MatrixError::EmptyCharset when CharSet::Custom resolves to an empty Vec, and MatrixError::InvalidConfig when any character in a charset is a char::is_control.

Boundary values are accepted: density == 0.0 / 1.0, min_trail == max_trail, mutation_rate == 0.0 / 1.0, glitch == 0.0 / 1.0.

Trait Implementations§

Source§

impl Clone for MatrixConfigBuilder

Source§

fn clone(&self) -> MatrixConfigBuilder

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 MatrixConfigBuilder

Source§

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

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

impl Default for MatrixConfigBuilder

Source§

fn default() -> Self

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> 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
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<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, 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