[−][src]Struct ruby_string::RubyString
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]
fn clone(&self) -> RubyString
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Default for RubyString
[src]
impl Eq for RubyString
[src]
impl<'a> Extend<Segment<'a>> for RubyString
[src]
fn extend<I: IntoIterator<Item = Segment<'a>>>(&mut self, iter: I)
[src]
fn extend_one(&mut self, item: A)
[src]
fn extend_reserve(&mut self, additional: usize)
[src]
impl<T: Into<String>> From<T> for RubyString
[src]
fn from(val: T) -> RubyString
[src]
impl<'a> FromIterator<Segment<'a>> for RubyString
[src]
fn from_iter<I: IntoIterator<Item = Segment<'a>>>(iter: I) -> RubyString
[src]
impl PartialEq<RubyString> for RubyString
[src]
fn eq(&self, other: &RubyString) -> bool
[src]
fn ne(&self, other: &RubyString) -> bool
[src]
impl StructuralEq for RubyString
[src]
impl StructuralPartialEq for RubyString
[src]
Auto Trait Implementations
impl RefUnwindSafe for RubyString
impl Send for RubyString
impl Sync for RubyString
impl Unpin for RubyString
impl UnwindSafe for RubyString
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,