pub struct TextString<'a>(/* private fields */);Expand description
Conversion helper for Value::text_string.
Wraps a Cow<'a, str> so that Value::text_string can accept
owned and borrowed string inputs through a single
impl Into<TextString> bound. This mirrors how Array
and Map abstract their input shapes.
Supported source types:
&'a str(and any&'a TwithT: AsRef<str>) borrows zero-copy.- Owned
Stringis moved without copying. Cow<'a, str>is preserved as-is.charallocates a one-characterString.
// Borrows from the literal:
let v = Value::text_string("hello");
assert_eq!(v.as_str().unwrap(), "hello");
// Owns its storage:
let v = Value::text_string(String::from("hello"));
assert_eq!(v.as_str().unwrap(), "hello");Implementations§
Source§impl<'a> TextString<'a>
impl<'a> TextString<'a>
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Create an empty text string.
The result is Cow::Borrowed("") and lives for any lifetime.
Sourcepub fn as_string_mut(&mut self) -> &mut String
pub fn as_string_mut(&mut self) -> &mut String
Borrow the contents as a mutable String, cloning if the
inner Cow is currently borrowed.
Sourcepub fn into_owned<'b>(self) -> TextString<'b>
pub fn into_owned<'b>(self) -> TextString<'b>
Detach from any borrow, returning a TextString with an
independent lifetime.
A borrowed TextString<'a> is copied into an owned String;
an already-owned one is returned unchanged. The result can
be assigned to any lifetime, in particular TextString<'static>.
Trait Implementations§
Source§impl<'a> Clone for TextString<'a>
impl<'a> Clone for TextString<'a>
Source§fn clone(&self) -> TextString<'a>
fn clone(&self) -> TextString<'a>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<'a> Debug for TextString<'a>
impl<'a> Debug for TextString<'a>
Source§impl<'a> Default for TextString<'a>
impl<'a> Default for TextString<'a>
Source§fn default() -> TextString<'a>
fn default() -> TextString<'a>
Returns the “default value” for a type. Read more
Source§impl<'a, T> From<&'a T> for TextString<'a>
impl<'a, T> From<&'a T> for TextString<'a>
Source§impl<'a> From<String> for TextString<'a>
impl<'a> From<String> for TextString<'a>
Source§impl<'a> From<TextString<'a>> for Value<'a>
impl<'a> From<TextString<'a>> for Value<'a>
Source§fn from(value: TextString<'a>) -> Self
fn from(value: TextString<'a>) -> Self
Converts to this type from the input type.
Source§impl<'a> From<char> for TextString<'a>
impl<'a> From<char> for TextString<'a>
Source§impl<'a> Hash for TextString<'a>
impl<'a> Hash for TextString<'a>
Source§impl<'a> Ord for TextString<'a>
impl<'a> Ord for TextString<'a>
Source§fn cmp(&self, other: &TextString<'a>) -> Ordering
fn cmp(&self, other: &TextString<'a>) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<'a> PartialEq for TextString<'a>
impl<'a> PartialEq for TextString<'a>
Source§impl<'a> PartialOrd for TextString<'a>
impl<'a> PartialOrd for TextString<'a>
impl<'a> Eq for TextString<'a>
impl<'a> StructuralPartialEq for TextString<'a>
Auto Trait Implementations§
impl<'a> Freeze for TextString<'a>
impl<'a> RefUnwindSafe for TextString<'a>
impl<'a> Send for TextString<'a>
impl<'a> Sync for TextString<'a>
impl<'a> Unpin for TextString<'a>
impl<'a> UnsafeUnpin for TextString<'a>
impl<'a> UnwindSafe for TextString<'a>
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
Mutably borrows from an owned value. Read more
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Casts the value.
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Casts the value.
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Casts the value.
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> StrictAs for T
impl<T> StrictAs for T
Source§fn strict_as<Dst>(self) -> Dstwhere
T: StrictCast<Dst>,
fn strict_as<Dst>(self) -> Dstwhere
T: StrictCast<Dst>,
Casts the value.
Source§impl<Src, Dst> StrictCastFrom<Src> for Dstwhere
Src: StrictCast<Dst>,
impl<Src, Dst> StrictCastFrom<Src> for Dstwhere
Src: StrictCast<Dst>,
Source§fn strict_cast_from(src: Src) -> Dst
fn strict_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> UnwrappedAs for T
impl<T> UnwrappedAs for T
Source§fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
Casts the value.
Source§impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
Source§fn unwrapped_cast_from(src: Src) -> Dst
fn unwrapped_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> WrappingAs for T
impl<T> WrappingAs for T
Source§fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
Source§fn wrapping_cast_from(src: Src) -> Dst
fn wrapping_cast_from(src: Src) -> Dst
Casts the value.