BioReader

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, left: String, right: String) -> Self

Set the strings to be wrapped around the emphasized part of a word. Default to bold if environment supports it.

§Example
use bio_read::BioReader;
let reader = BioReader::new()
    .emphasize(String::from("<em>"), String::from("</em>"))
    .de_emphasize(String::from(""), String::from(""));
assert_eq!(reader.bio_read_text("hello world").unwrap(), "<em>hel</em>lo <em>wor</em>ld");
§See also

Other methods that can be used to customize the BioReader:

Source

pub fn de_emphasize(self, left: String, right: String) -> Self

Set the strings to be wrapped around the de-emphasized part of a word. Default to dimmed if environment supports it.

§Example
use bio_read::BioReader;
let reader = BioReader::new()
   .emphasize(String::from(""), String::from(""))
    .de_emphasize(String::from("<de>"), String::from("</de>"));
assert_eq!(reader.bio_read_text("hello world").unwrap(), "hel<de>lo</de> wor<de>ld</de>");
§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 markdownBold = String::from("**");
let empty = String::from("");
let reader = BioReader::new()
    .emphasize(markdownBold.clone(), markdownBold.clone())
    .de_emphasize(empty.clone(), empty.clone())
    .fixation_point(1); // Set fixation point to 1
assert_eq!(reader.bio_read_text("pneumonoultramicroscopicsilicovolcanoconiosis").unwrap(), "**pneumonoultramicroscopicsilicovolcano**coniosis");
let reader = BioReader::new()
    .emphasize(markdownBold.clone(), markdownBold.clone())
    .de_emphasize(empty.clone(), empty.clone())
    .fixation_point(5); // Set fixation point to 5
assert_eq!(reader.bio_read_text("pneumonoultramicroscopicsilicovolcanoconiosis").unwrap(), "**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(&self, reader: impl Read, writer: &mut impl Write) -> Result<()>

Do bio-reading on reader and write the result to writer.

§Performance

This method guarantees linear time complexity and constant memory usage.

§Example
use bio_read::BioReader;
use std::io::Write;
let reader = BioReader::new()
    .emphasize(String::from("<em>"), String::from("</em>"))
    .de_emphasize(String::from("<de>"), String::from("</de>"));
let mut output_buffer = Vec::new();
reader.bio_read("hello world".as_bytes(), &mut output_buffer).unwrap();
let output = String::from_utf8(output_buffer).unwrap();
assert_eq!(output, "<em>hel</em><de>lo</de> <em>wor</em><de>ld</de>");
§See also

BioReader::bio_read_text: A simple wrapper around BioReader::bio_read for processing short strings.

Source

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

Do bio-reading on a piece of text. This is a simple wrapper for processing short strings. If you intend to process large files or work with streams, use BioReader::bio_read instead.

§Example
use bio_read::BioReader;
let reader = BioReader::new()
    .emphasize(String::from("<em>"), String::from("</em>"))
    .de_emphasize(String::from("<de>"), String::from("</de>"));
let output = reader.bio_read_text("hello world").unwrap();
assert_eq!(output, "<em>hel</em><de>lo</de> <em>wor</em><de>ld</de>");
§See also

BioReader::bio_read: Do bio-reading on reader and write the result to writer.

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.