bio_read

Struct BioReader

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

A BioReader object, allowing for customizing the bio-reading experience.

Implementations§

Source§

impl BioReader

Source

pub fn new() -> Self

Create a new BioReader object.

Source

pub fn emphasize(self, f: fn(_: &str) -> String) -> Self

Set the function to emphasize part of a word. Default to bold if environment supports it.

§Example
use bio_read::BioReader;
let reader = BioReader::new().emphasize(|s| format!("**{s}**")); // Emphasize by wrapping with `**`
assert_eq!(reader.bio_read_text("hello world"), "**hel**lo **wor**ld");
§See also

Other methods that can be used to customize the BioReader:

Source

pub fn de_emphasize(self, f: fn(_: &str) -> String) -> Self

Set the function to de-emphasize part of a word. Default to dimmed if environment supports it.

§Example
use bio_read::BioReader;
let reader = BioReader::new().de_emphasize(|s| format!("_{s}_")); // De-emphasize by wrapping with `_`
assert_eq!(reader.bio_read_text("hello world"), "hel_lo_ wor_ld_");
§See also

Other methods that can be used to customize the BioReader:

Source

pub fn fixation_point(self, fixation_point: usize) -> Self

Set the fixation point. The lower the fixation point, the more characters will be emphasized. The fixation_point should be in range [1, 5], defaulting to 3 when not specified.

§Example
use bio_read::BioReader;
let reader = BioReader::new()
    .emphasize(|s| format!("**{s}**"))
    .fixation_point(1); // Set fixation point to 1
assert_eq!(reader.bio_read_word("pneumonoultramicroscopicsilicovolcanoconiosis"), "**pneumonoultramicroscopicsilicovolcano**coniosis");
let reader = BioReader::new()
    .emphasize(|s| format!("**{s}**"))
    .fixation_point(5); // Set fixation point to 5
assert_eq!(reader.bio_read_word("pneumonoultramicroscopicsilicovolcanoconiosis"), "**pneumonoult**ramicroscopicsilicovolcanoconiosis");
§Panics

Panics if fixation_point is not in range [1, 5].

§See also

Other methods that can be used to customize the BioReader:

Source

pub fn bio_read_word(&self, word: &str) -> String

Do bio-reading on a word.

§See also

BioReader::bio_read_text: Do bio-reading on a piece of text.

Source

pub fn bio_read_text(&self, text: &str) -> String

Do bio-reading on a piece of text.

§See also

BioReader::bio_read_word: Do bio-reading on a word.

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