pub struct RichString {
pub elements: Vec<Element>,
}Expand description
A string that can have different parts styled.
New lines will always appear as their own non styled element.
The RichString is comprised of a collection of Elements that each
hold a String and a combination of stylings. The available styles are:
**bold**→ bold*italic*→ italic_underline_→ underline
as specified in the Fountain specification.
Emphasis is parsed in accordance to the CommonMark specification.
Furthermore, these can be combined in any overlapping order. Use \ for a styling character to be
ignored for style parsing.
§Examples
use rustwell::rich_string::RichString;
let mut rs = RichString::from("Hello **world!**");
assert_eq!(rs.elements[0].text, "Hello ".to_string());
assert_eq!(rs.elements[1].text, "world!".to_string());
assert!(rs.elements[1].is_bold());Fields§
§elements: Vec<Element>Implementations§
Source§impl RichString
impl RichString
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new, empty, RichString.
Sourcepub fn char_count(&self) -> usize
pub fn char_count(&self) -> usize
The total length of a RichString, meaning the total number of chars.
Sourcepub fn get_char(&self, index: usize) -> Option<char>
pub fn get_char(&self, index: usize) -> Option<char>
Gets a char from a “global” index, meaning the index when viewing the RichString as
a single string without any style attributes taken into account.
§Examples
use rustwell::rich_string::RichString;
let mut rs = RichString::from("He**llo**");
assert_eq!(rs.get_char(1), Some('e'));
assert_eq!(rs.get_char(3), Some('l'));
assert_eq!(rs.get_char(5), None);Sourcepub fn get_element_from_index(&self, index: usize) -> Option<(&Element, usize)>
pub fn get_element_from_index(&self, index: usize) -> Option<(&Element, usize)>
Given a “global” index, gets the Element which contains it, and the “local” index
pointing to that character in the element.
§Examples
use rustwell::rich_string::RichString;
let mut rs = RichString::from("He**ll**o");
assert!(matches!(rs.get_element_from_index(1), Some((_, 1))));
assert!(matches!(rs.get_element_from_index(2), Some((_, 0))));
assert!(matches!(rs.get_element_from_index(3), Some((_, 1))));
assert!(matches!(rs.get_element_from_index(4), Some((_, 0))));Sourcepub fn iter(&self) -> RichIterator<'_> ⓘ
pub fn iter(&self) -> RichIterator<'_> ⓘ
Creates an char iterator over the RichString, without the style attributes of each
char taken into account.
Sourcepub fn append(&mut self, other: Self)
pub fn append(&mut self, other: Self)
Appends a RichString to self. Will merge the last Element of self, and the
first of the other if they have the same style attributes.
Sourcepub fn push_str(&mut self, str: impl AsRef<str>)
pub fn push_str(&mut self, str: impl AsRef<str>)
Pushes a string onto the RichString. Will divide the string into
multiple elements with different styles if input string can be parsed with styles.
Sourcepub fn to_plain_string(&self) -> String
pub fn to_plain_string(&self) -> String
Converts the RichString to a plain String by just combining the string elements
without adding delimiters.
§Examples
use rustwell::rich_string::RichString;
let mut rs = RichString::from("He**ll**o");
assert_eq!(rs.to_plain_string(), "Hello".to_string());Trait Implementations§
Source§impl Clone for RichString
impl Clone for RichString
Source§impl Debug for RichString
impl Debug for RichString
Source§impl Default for RichString
impl Default for RichString
Source§impl Display for RichString
impl Display for RichString
impl Eq for RichString
Source§impl<T> From<T> for RichString
impl<T> From<T> for RichString
Source§impl Hash for RichString
impl Hash for RichString
Source§impl PartialEq for RichString
impl PartialEq for RichString
impl StructuralPartialEq for RichString
Auto Trait Implementations§
impl Freeze for RichString
impl RefUnwindSafe for RichString
impl Send for RichString
impl Sync for RichString
impl Unpin for RichString
impl UnsafeUnpin for RichString
impl UnwindSafe for RichString
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
Source§fn to_owned_obj(&self, data: FontData<'_>) -> U
fn to_owned_obj(&self, data: FontData<'_>) -> U
T, using the provided data to resolve any offsets.