emit

Struct Str

Source
pub struct Str<'k> { /* private fields */ }
Expand description

A string value.

The Str::get method can be used to operate on the value as if it’s a standard str. Equality, ordering, and hashing all defer to the str representation.

The value may internally be any one of:

  • &'k str.
  • &'static str.
  • Box<str>.
  • Arc<str>.

Implementations§

Source§

impl Str<'static>

Source

pub const fn new(k: &'static str) -> Str<'static>

Create a new string from a value borrowed for 'static.

Source§

impl<'k> Str<'k>

Source

pub const fn new_ref(k: &'k str) -> Str<'k>

Create a new string from a value borrowed for 'k.

The Str::new method should be preferred where possible.

Source

pub const fn by_ref<'b>(&'b self) -> Str<'b>

Get a new string, borrowing data from this one.

Source

pub const fn get(&self) -> &str

Get a reference to the underlying value.

Source

pub const fn get_static(&self) -> Option<&'static str>

Try get a reference to the underlying static value.

If the string was created from Str::new and contains a 'static value then this method will return Some. Otherwise this method will return None.

Source§

impl Str<'static>

Source

pub fn new_owned(key: impl Into<Box<str>>) -> Str<'static>

Create a string from an owned value.

Cloning the string will involve cloning the value.

Source

pub fn new_shared(key: impl Into<Arc<str>>) -> Str<'static>

Create a string from a shared value.

Cloning the string will involve cloning the Arc, which may be cheaper than cloning the value itself.

Source§

impl<'k> Str<'k>

Source

pub fn new_cow_ref(key: Cow<'k, str>) -> Str<'k>

Create a string from a potentially owned value.

If the value is Cow::Borrowed then this method will defer to Str::new_ref. If the value is Cow::Owned then this method will defer to Str::new_owned.

Source

pub fn to_cow(&self) -> Cow<'static, str>

Get the underlying value as a potentially owned string.

If the string contains a 'static value then this method will return Cow::Borrowed. Otherwise it will return Cow::Owned.

Source

pub fn to_owned(&self) -> Str<'static>

Get a new string, taking an owned copy of the data in this one.

If the string contains a 'static or Arc value then this method is cheap and doesn’t involve cloning. In other cases the underlying value will be passed through Str::new_owned.

Source

pub fn into_string(self) -> String

Convert this string into an owned String.

If the underlying value is already an owned string then this method will return it without allocating.

Source

pub fn to_shared(&self) -> Str<'static>

Get a new string, taking an owned copy of the data in this one.

If the string contains a 'static or Arc value then this method is cheap and doesn’t involve cloning. In other cases the underlying value will be passed through Str::new_shared.

Trait Implementations§

Source§

impl<'k> AsRef<str> for Str<'k>

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'k> Borrow<str> for Str<'k>

Source§

fn borrow(&self) -> &str

Immutably borrows from an owned value. Read more
Source§

impl<'k> Clone for Str<'k>

Source§

fn clone(&self) -> Str<'k>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'k> Debug for Str<'k>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'k> Display for Str<'k>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'k> Drop for Str<'k>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<'a, 'b> From<&'a Str<'b>> for Str<'a>

Source§

fn from(value: &'a Str<'b>) -> Str<'a>

Converts to this type from the input type.
Source§

impl<'k> From<&'k String> for Str<'k>

Source§

fn from(value: &'k String) -> Str<'k>

Converts to this type from the input type.
Source§

impl<'a> From<&'a str> for Str<'a>

Source§

fn from(value: &'a str) -> Str<'a>

Converts to this type from the input type.
Source§

impl From<Arc<str>> for Str<'static>

Source§

fn from(value: Arc<str>) -> Str<'static>

Converts to this type from the input type.
Source§

impl From<Box<str>> for Str<'static>

Source§

fn from(value: Box<str>) -> Str<'static>

Converts to this type from the input type.
Source§

impl From<String> for Str<'static>

Source§

fn from(value: String) -> Str<'static>

Converts to this type from the input type.
Source§

impl<'k> FromValue<'k> for Str<'k>

Source§

fn from_value<'a>(value: Value<'k>) -> Option<Str<'k>>

Perform the conversion.
Source§

impl<'a> Hash for Str<'a>

Source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a> Ord for Str<'a>

Source§

fn cmp(&self, other: &Str<'a>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<'a, 'b> PartialEq<&'b str> for Str<'a>

Source§

fn eq(&self, other: &&'b str) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, 'b> PartialEq<Path<'b>> for Str<'a>

Source§

fn eq(&self, other: &Path<'b>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> PartialEq<Str<'a>> for str

Source§

fn eq(&self, other: &Str<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, 'b> PartialEq<Str<'b>> for &'a str

Source§

fn eq(&self, other: &Str<'b>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, 'b> PartialEq<Str<'b>> for Path<'a>

Source§

fn eq(&self, other: &Str<'b>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, 'b> PartialEq<Str<'b>> for Str<'a>

Source§

fn eq(&self, other: &Str<'b>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> PartialEq<str> for Str<'a>

Source§

fn eq(&self, other: &str) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, 'b> PartialOrd<Str<'b>> for Str<'a>

Source§

fn partial_cmp(&self, other: &Str<'b>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'k> Serialize for Str<'k>

Source§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<'k> ToStr for Str<'k>

Source§

fn to_str(&self) -> Str<'_>

Perform the conversion.
Source§

impl<'k> ToValue for Str<'k>

Source§

fn to_value(&self) -> Value<'_>

Perform the conversion.
Source§

impl<'k> Value for Str<'k>

Source§

fn stream<'sval, S>(&'sval self, stream: &mut S) -> Result<(), Error>
where S: Stream<'sval> + ?Sized,

Stream this value through a Stream.
Source§

fn tag(&self) -> Option<Tag>

Get the tag of this value, if there is one.
Source§

fn to_bool(&self) -> Option<bool>

Try convert this value into a boolean.
Source§

fn to_f32(&self) -> Option<f32>

Try convert this value into a 32bit binary floating point number.
Source§

fn to_f64(&self) -> Option<f64>

Try convert this value into a 64bit binary floating point number.
Source§

fn to_i8(&self) -> Option<i8>

Try convert this value into a signed 8bit integer.
Source§

fn to_i16(&self) -> Option<i16>

Try convert this value into a signed 16bit integer.
Source§

fn to_i32(&self) -> Option<i32>

Try convert this value into a signed 32bit integer.
Source§

fn to_i64(&self) -> Option<i64>

Try convert this value into a signed 64bit integer.
Source§

fn to_i128(&self) -> Option<i128>

Try convert this value into a signed 128bit integer.
Source§

fn to_u8(&self) -> Option<u8>

Try convert this value into an unsigned 8bit integer.
Source§

fn to_u16(&self) -> Option<u16>

Try convert this value into an unsigned 16bit integer.
Source§

fn to_u32(&self) -> Option<u32>

Try convert this value into an unsigned 32bit integer.
Source§

fn to_u64(&self) -> Option<u64>

Try convert this value into an unsigned 64bit integer.
Source§

fn to_u128(&self) -> Option<u128>

Try convert this value into an unsigned 128bit integer.
Source§

fn to_text(&self) -> Option<&str>

Try convert this value into a text string.
Source§

fn to_binary(&self) -> Option<&[u8]>

Try convert this value into a bitstring.
Source§

impl<'k> ValueRef<'k> for Str<'k>

Source§

fn stream_ref<S>(&self, stream: &mut S) -> Result<(), Error>
where S: Stream<'k> + ?Sized,

Stream this value through a Stream.
Source§

impl<'a> Eq for Str<'a>

Source§

impl<'k> Send for Str<'k>

Source§

impl<'k> Sync for Str<'k>

Auto Trait Implementations§

§

impl<'k> Freeze for Str<'k>

§

impl<'k> RefUnwindSafe for Str<'k>

§

impl<'k> Unpin for Str<'k>

§

impl<'k> UnwindSafe for Str<'k>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> Value for T
where T: Value,