Skip to main content

FilterChain

Struct FilterChain 

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

Ordered list of Filters applied left-to-right in FilterChain::apply (FR-004).

§Cost bound

A chain of n filters applied to a w × h grid runs in O(n · w · h) time and allocates at most O(w · h) per step (per AD-002 + AD-007 + HINT-006 + FR-022 + FR-030). The grid is owned and cloned-on-write between steps, so memory peaks at one extra grid above the input.

SC-012 records the wall-clock linear-scaling guarantee (tests/filter_scaling.rs asserts N=20 ≤ 2.5× N=10). HINT-002 surfaces this bound to library consumers via this rustdoc.

§Construction

Build programmatically via FilterChain::new + FilterChain::push (per US5), or parse from a -F flag string via FilterChain::parse (per FR-002). Parsing handles the filter1:filter2:... syntax shared with toilet(1); the CLI concatenates multiple -F flags with : before invoking parse.

use rusty_figlet::filter::{Filter, FilterChain, RenderGrid};

// Programmatic composition (US5).
let chain = FilterChain::new()
    .push(Filter::Crop)
    .push(Filter::Border);

// Parsed from a `-F` flag.
let parsed = FilterChain::parse("crop:border").expect("parse");
assert_eq!(chain, parsed);

let grid = RenderGrid::blank(4, 2);
let _ = chain.apply(grid).expect("apply");

Implementations§

Source§

impl FilterChain

Source

pub fn new() -> Self

Construct an empty chain.

An empty chain applied to a grid returns the input unchanged.

Source

pub fn push(self, filter: Filter) -> Self

Append filter to this chain and return the updated chain (consuming-self builder per US5 ergonomics).

Source

pub fn parse(spec: &str) -> Result<FilterChain, FigletError>

Parse a -F <chain> specification per FR-002.

Syntax: filter1:filter2:... — colon-separated lowercase names. Multiple -F CLI flags are concatenated with : by the caller before invoking parse.

Empty segments (crop::flip), names longer than 64 bytes, and names not in the canonical list (case-sensitive) are all rejected with FigletError::UnknownFilter whose available field enumerates the 10 valid names in declaration order (per FR-016 and spec Edge Cases). An entirely empty spec parses to an empty chain (the no--F-flag case).

Source

pub fn len(&self) -> usize

Number of filters currently in this chain.

Source

pub fn is_empty(&self) -> bool

true when this chain has no filters; apply would return its input unchanged.

Source

pub fn filters(&self) -> &[Filter]

Borrow the chain’s filters in application order.

Source

pub fn apply(&self, grid: RenderGrid) -> Result<RenderGrid, FigletError>

Apply each filter in order to grid and return the resulting grid (FR-004).

§Cost bound (FR-030 + HINT-006 + AD-007)

Runs in O(n · w · h) where n = self.filters().len(), w = grid.width, h = grid.height. SC-012 enforces a wall-clock linear-scaling test on the library so callers can rely on this bound when composing long chains programmatically (US5).

Empty chains are well-defined — they return the input grid unchanged. Filters whose leaf feature is disabled at compile-time return a FigletError::UnknownFilter at apply time rather than at construction time so existing FilterChain values keep working when reused across builds with different feature surfaces.

Trait Implementations§

Source§

impl Clone for FilterChain

Source§

fn clone(&self) -> FilterChain

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 FilterChain

Source§

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

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

impl Default for FilterChain

Source§

fn default() -> FilterChain

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

impl PartialEq for FilterChain

Source§

fn eq(&self, other: &FilterChain) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for FilterChain

Source§

impl StructuralPartialEq for FilterChain

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