Skip to main content

StaticString

Trait StaticString 

Source
pub trait StaticString:
    Sealed
    + Sized
    + Send
    + Sync
    + 'static {
    // Required methods
    fn into_cow(self) -> Cow<'static, str>;
    fn into_owned(self) -> String;
    fn try_borrow(&self) -> Option<&'static str>;
}
Expand description

Allow for access and conversion from a static string asset.

This is useful for allowing a relaxed reliance on the alloc crate. If the alloc feature is not enabled, you cannot use types that would require taking ownership of an allocated string.

This is to explicitly avoid naming String in places.

Required Methods§

Source

fn into_cow(self) -> Cow<'static, str>

Available on crate feature alloc only.

Take CoW ownership of the provided static string.

Source

fn into_owned(self) -> String

Available on crate feature alloc only.

Take ownership of the provided static string.

Source

fn try_borrow(&self) -> Option<&'static str>

Attempt to borrow the string as a static string reference.

This can fail if the type this is implemented over does not contain a static reference to a string (e.g. it’s an allocated String).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl StaticString for &'static str

Source§

fn into_cow(self) -> Cow<'static, str>

Available on crate feature alloc only.
Source§

fn into_owned(self) -> String

Available on crate feature alloc only.
Source§

fn try_borrow(&self) -> Option<&'static str>

Source§

impl StaticString for Cow<'static, str>

Available on crate feature alloc only.
Source§

fn into_cow(self) -> Cow<'static, str>

Source§

fn into_owned(self) -> String

Source§

fn try_borrow(&self) -> Option<&'static str>

Source§

impl StaticString for String

Available on crate feature alloc only.
Source§

fn into_cow(self) -> Cow<'static, str>

Source§

fn into_owned(self) -> String

Source§

fn try_borrow(&self) -> Option<&'static str>

Implementors§