stylish_stringlike/text/
mod.rs

1//! Provides the primary text object, [`Spans`], which is a sequence
2//! of styled spans, as well as traits providing support for string-like
3//! methods on structs.
4
5mod expandable;
6mod joinable;
7mod paintable;
8mod pushable;
9mod replaceable;
10mod sliceable;
11mod spans;
12mod splitable;
13mod tag;
14mod width;
15mod width_sliceable;
16pub use expandable::Expandable;
17pub use joinable::Joinable;
18pub use paintable::Paintable;
19pub use pushable::Pushable;
20pub use replaceable::*;
21pub use sliceable::*;
22pub use spans::*;
23pub use splitable::*;
24pub use tag::*;
25pub use width::*;
26pub use width_sliceable::*;
27
28/// Support for converting a text object into a raw, unstyled string
29pub trait RawText {
30    /// Return an owned copy of the raw contents of the text object.
31    ///
32    /// # Example
33    /// ```
34    /// use stylish_stringlike::text::RawText;
35    /// let foo = String::from("foobar");
36    /// assert_eq!(foo.raw(), foo);
37    /// ````
38    fn raw(&self) -> String;
39    /// Return a reference ot the raw contents of the text object.
40    ///
41    /// # Example
42    /// ```
43    /// use stylish_stringlike::text::RawText;
44    /// let foo = String::from("foobar");
45    /// assert_eq!(foo.raw_ref(), &foo);
46    /// ```
47    fn raw_ref(&self) -> &str;
48}
49
50impl RawText for String {
51    fn raw(&self) -> String {
52        self.clone()
53    }
54    fn raw_ref(&self) -> &str {
55        self.as_str()
56    }
57}
58
59impl RawText for &str {
60    fn raw(&self) -> String {
61        self.to_string()
62    }
63    fn raw_ref(&self) -> &str {
64        *self
65    }
66}