[][src]Struct ruby_string::RubyString

pub struct RubyString { /* fields omitted */ }

A string type that can have ruby glosses attached to parts of it.

Memory layout

The text content is stored in two String instances, one being the main text and one being a concatenation of all the rubies. Placement of the rubies is stored as a list of indices into both strings. Compared to the trivial structure (where each rubied substring is held as a separate String), this layout reduces memory usage and the number of separate allocations at the expense of slightly more complicated indexing logic.

Implementations

impl RubyString[src]

pub fn new() -> RubyString[src]

Creates a new empty RubyString.

pub fn push_str(&mut self, string: &str)[src]

Appends plain text (that does not have a ruby gloss attached to it) to this RubyString.

pub fn push_segment<'a>(&mut self, segment: Segment<'a>)[src]

Appends text to this RubyString and attaches a ruby gloss to it.

pub fn to_plain_text(&self) -> String[src]

Returns the plain text stored in this RubyString. The result has no ruby glosses attached to it anymore.

let mut rs = RubyString::new();
rs.push_str("ここは");
rs.push_segment(Segment::Rubied { text: "東", ruby: "とう" });
rs.push_segment(Segment::Rubied { text: "京", ruby: "きょう" });
rs.push_str("です");
assert_eq!(rs.to_plain_text(), "ここは東京です");

pub fn to_interlinear_encoding(&self) -> String[src]

Returns an encoding of this RubyString as a plain String using interlinear annotation characters.

let mut rs = RubyString::new();
rs.push_str("ここは");
rs.push_segment(Segment::Rubied { text: "東", ruby: "とう" });
rs.push_segment(Segment::Rubied { text: "京", ruby: "きょう" });
rs.push_str("です");
let encoded = rs.to_interlinear_encoding();
assert_eq!(encoded, "ここは\u{FFF9}東\u{FFFA}とう\u{FFFB}\u{FFF9}京\u{FFFA}きょう\u{FFFB}です");

pub fn segments(&self) -> SegmentIterator[src]

An iterator over the segments in this RubyString.

Trait Implementations

impl Clone for RubyString[src]

impl Default for RubyString[src]

impl Eq for RubyString[src]

impl<'a> Extend<Segment<'a>> for RubyString[src]

impl<T: Into<String>> From<T> for RubyString[src]

impl<'a> FromIterator<Segment<'a>> for RubyString[src]

impl PartialEq<RubyString> for RubyString[src]

impl StructuralEq for RubyString[src]

impl StructuralPartialEq for RubyString[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.