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
impl MatrixConfigBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Returns a new builder seeded with MatrixConfig::default.
Sourcepub fn speed(self, speed: f32) -> Self
pub fn speed(self, speed: f32) -> Self
Set the global speed multiplier. Must be finite and > 0.0.
Sourcepub fn density(self, density: f32) -> Self
pub fn density(self, density: f32) -> Self
Set the column-activity density. Must be finite and in [0.0, 1.0].
Sourcepub fn min_trail(self, min_trail: u16) -> Self
pub fn min_trail(self, min_trail: u16) -> Self
Set the minimum trail length. Must be >= 1 and <= max_trail.
Sourcepub fn max_trail(self, max_trail: u16) -> Self
pub fn max_trail(self, max_trail: u16) -> Self
Set the maximum trail length. Must be <= MAX_TRAIL_LIMIT.
Sourcepub fn mutation_rate(self, mutation_rate: f32) -> Self
pub fn mutation_rate(self, mutation_rate: f32) -> Self
Set the per-cell glyph reroll probability per tick. Finite, [0.0, 1.0].
Sourcepub fn bold_head(self, bold_head: bool) -> Self
pub fn bold_head(self, bold_head: bool) -> Self
Apply Modifier::BOLD to the head cell when true.
Sourcepub fn head_white(self, head_white: bool) -> Self
pub fn head_white(self, head_white: bool) -> Self
Use ColorRamp.head for the head cell when true, ColorRamp.bright
when false.
Sourcepub fn glitch(self, glitch: f32) -> Self
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.
Sourcepub fn background(self, background: Option<Color>) -> Self
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.
Sourcepub fn build(self) -> Result<MatrixConfig, MatrixError>
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 >= 1speedis finite and> 0densityis finite and in[0.0, 1.0]min_trail >= 1min_trail <= max_trailmax_trail <= MAX_TRAIL_LIMITmutation_rateis finite and in[0.0, 1.0]glitchis 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
impl Clone for MatrixConfigBuilder
Source§fn clone(&self) -> MatrixConfigBuilder
fn clone(&self) -> MatrixConfigBuilder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MatrixConfigBuilder
impl Debug for MatrixConfigBuilder
Auto Trait Implementations§
impl Freeze for MatrixConfigBuilder
impl RefUnwindSafe for MatrixConfigBuilder
impl Send for MatrixConfigBuilder
impl Sync for MatrixConfigBuilder
impl Unpin for MatrixConfigBuilder
impl UnsafeUnpin for MatrixConfigBuilder
impl UnwindSafe for MatrixConfigBuilder
Blanket Implementations§
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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