pub struct Text { /* private fields */ }Expand description
Text of a string or an atom.
The platform keeps text as UTF-16 code units and writes each surrogate of a quoted string
as an escape "\xxxx, so a string may hold an unpaired surrogate. Text keeps such
strings without losses; as_str gives None for them and
to_string_lossy replaces unpaired surrogates with U+FFFD.
Stored as WTF-8: UTF-8 that also encodes unpaired surrogates. Text without them is plain UTF-8.
Implementations§
Source§impl Text
impl Text
pub fn new() -> Self
Sourcepub fn from_utf16(units: &[u16]) -> Self
pub fn from_utf16(units: &[u16]) -> Self
Text from UTF-16 code units; unpaired surrogates are kept.
Sourcepub fn to_string_lossy(&self) -> Cow<'_, str>
pub fn to_string_lossy(&self) -> Cow<'_, str>
The text with unpaired surrogates replaced by U+FFFD.
Sourcepub fn into_string(self) -> Result<String, Text>
pub fn into_string(self) -> Result<String, Text>
The text as a String; Err gives it back if it holds an unpaired surrogate.
Sourcepub fn encode_utf16(&self) -> impl Iterator<Item = u16> + '_
pub fn encode_utf16(&self) -> impl Iterator<Item = u16> + '_
UTF-16 code units, as the platform keeps the text.
Sourcepub fn code_points(&self) -> impl Iterator<Item = u32> + '_
pub fn code_points(&self) -> impl Iterator<Item = u32> + '_
Unicode code points; unpaired surrogates come as themselves (0xD800..=0xDFFF).
pub fn is_empty(&self) -> bool
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Text
Available on crate feature serde only.
impl<'de> Deserialize<'de> for Text
serde only.Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
impl Eq for Text
Source§impl Ord for Text
impl Ord for Text
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Text
impl PartialOrd for Text
Source§impl Serialize for Text
Available on crate feature serde only.Positions are not written: they belong to the parsed text.
A string; text with an unpaired surrogate cannot be serialized.
impl Serialize for Text
serde only.Positions are not written: they belong to the parsed text. A string; text with an unpaired surrogate cannot be serialized.