pub struct Options { /* private fields */ }Expand description
Algorithm options with the spec defaults (SPEC §4).
Build them with the chaining setters; every value is clamped into range
rather than rejected, exactly as in every other port: fixation to 1..=5,
saccade to >= 1. Negative values cannot be expressed in the first place
(u8/usize), which the spec allows a port whose type system excludes them
to rely on.
The setters take self and return it, so a value can be configured in one
expression; the getters carry a get_ prefix (as on
std::process::Command) because the plain names are taken by the setters.
Options implements Clone and Debug but not
PartialEq: it can hold a closure and a segmenter, which have no useful
notion of equality.
use smooth_reading::Options;
let options = Options::new().fixation(4).saccade(2);
assert_eq!(options.get_fixation(), 4);
assert_eq!(options.get_saccade(), 2);
assert_eq!(Options::new().fixation(9).get_fixation(), 5); // clamped
assert_eq!(Options::new().saccade(0).get_saccade(), 1); // clampedImplementations§
Source§impl Options
impl Options
Sourcepub const fn new() -> Self
pub const fn new() -> Self
The spec defaults: strength 3, every word, no minimum length, numbers
not emphasised, no locale, the built-in algorithm and segmenter.
Sourcepub const fn fixation(self, fixation: u8) -> Self
pub const fn fixation(self, fixation: u8) -> Self
Sets the fixation strength, clamped to 1..=5. Default 3.
The strength selects the proportion of each word that is emphasised:
0.20, 0.35, 0.50, 0.65, 0.80.
Sourcepub const fn saccade(self, saccade: usize) -> Self
pub const fn saccade(self, saccade: usize) -> Self
Sets the saccade interval: emphasise every saccade-th word. Clamped to
>= 1. Default 1.
Sourcepub const fn min_word_length(self, min_word_length: usize) -> Self
pub const fn min_word_length(self, min_word_length: usize) -> Self
Words with fewer grapheme clusters than this get no fixation. Default 1.
Sourcepub const fn emphasize_numbers(self, emphasize_numbers: bool) -> Self
pub const fn emphasize_numbers(self, emphasize_numbers: bool) -> Self
Whether words made only of decimal digits are emphasised. Default false.
Sourcepub fn locale(self, locale: impl Into<String>) -> Self
pub fn locale(self, locale: impl Into<String>) -> Self
Sets the BCP-47 language tag passed to the segmenter. The built-in
SpecSegmenter ignores it; a platform break iterator may use it.
Sourcepub fn fixation_length<F>(self, fixation_length: F) -> Self
pub fn fixation_length<F>(self, fixation_length: F) -> Self
Replaces the built-in fixation algorithm (SPEC §2, “Custom override”).
fixation_length honours this override, so
the closure must not call it with the same options (that would recurse).
use smooth_reading::{Options, to_markdown};
// Always emphasise exactly one cluster (clamped to the word length).
let options = Options::new().fixation_length(|_word, _graphemes, _options| 1);
assert_eq!(to_markdown("Smooth reading", &options, "**"), "**S**mooth **r**eading");Sourcepub fn segmenter(self, segmenter: impl Segmenter + 'static) -> Self
pub fn segmenter(self, segmenter: impl Segmenter + 'static) -> Self
Supplies word boundaries and grapheme clusters (SPEC §3).
The default is the spec’s regular-expression scanner. Supply an
ICU-backed Segmenter for dictionary-based Chinese, Japanese and Thai
word breaks; the fixation algorithm itself never changes. The segmenter
is stored behind an Arc; use Options::shared_segmenter to share
one you already hold.
Like Options::segmenter, for a segmenter that is already shared
(for example one expensive to build and reused across many Options).
Sourcepub const fn get_fixation(&self) -> u8
pub const fn get_fixation(&self) -> u8
The fixation strength, 1..=5.
Sourcepub const fn get_saccade(&self) -> usize
pub const fn get_saccade(&self) -> usize
The saccade interval, >= 1.
Sourcepub const fn get_min_word_length(&self) -> usize
pub const fn get_min_word_length(&self) -> usize
The minimum word length (in grapheme clusters) that gets a fixation.
Sourcepub const fn get_emphasize_numbers(&self) -> bool
pub const fn get_emphasize_numbers(&self) -> bool
Whether digit-only words are emphasised.
Sourcepub fn get_locale(&self) -> Option<&str>
pub fn get_locale(&self) -> Option<&str>
The BCP-47 language tag, if one was set.
Sourcepub const fn get_fixation_length(&self) -> Option<&FixationLengthFn>
pub const fn get_fixation_length(&self) -> Option<&FixationLengthFn>
The custom fixation-length function, if one was set.
Sourcepub const fn get_segmenter(&self) -> Option<&Arc<dyn Segmenter>>
pub const fn get_segmenter(&self) -> Option<&Arc<dyn Segmenter>>
The custom segmenter, if one was set.