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
impl FilterChain
Sourcepub fn new() -> Self
pub fn new() -> Self
Construct an empty chain.
An empty chain applied to a grid returns the input unchanged.
Sourcepub fn push(self, filter: Filter) -> Self
pub fn push(self, filter: Filter) -> Self
Append filter to this chain and return the updated chain
(consuming-self builder per US5 ergonomics).
Sourcepub fn parse(spec: &str) -> Result<FilterChain, FigletError>
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).
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
true when this chain has no filters; apply would return its
input unchanged.
Sourcepub fn apply(&self, grid: RenderGrid) -> Result<RenderGrid, FigletError>
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
impl Clone for FilterChain
Source§fn clone(&self) -> FilterChain
fn clone(&self) -> FilterChain
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 FilterChain
impl Debug for FilterChain
Source§impl Default for FilterChain
impl Default for FilterChain
Source§fn default() -> FilterChain
fn default() -> FilterChain
Source§impl PartialEq for FilterChain
impl PartialEq for FilterChain
Source§fn eq(&self, other: &FilterChain) -> bool
fn eq(&self, other: &FilterChain) -> bool
self and other values to be equal, and is used by ==.