pub struct BioReader { /* private fields */ }Expand description
A BioReader object, allowing for customizing the bio-reading experience.
Implementations§
Source§impl BioReader
impl BioReader
Sourcepub fn emphasize(self, left: String, right: String) -> Self
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:
Sourcepub fn de_emphasize(self, left: String, right: String) -> Self
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:
Sourcepub fn fixation_point(self, fixation_point: usize) -> Self
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:
Sourcepub fn bio_read(&self, reader: impl Read, writer: &mut impl Write) -> Result<()>
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.
Sourcepub fn bio_read_text(&self, text: &str) -> Result<String, Error>
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.