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§
Sourcefn into_cow(self) -> Cow<'static, str>
Available on crate feature alloc only.
fn into_cow(self) -> Cow<'static, str>
alloc only.Take CoW ownership of the provided static string.
Sourcefn into_owned(self) -> String
Available on crate feature alloc only.
fn into_owned(self) -> String
alloc only.Take ownership of the provided static string.
Sourcefn try_borrow(&self) -> Option<&'static str>
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
impl StaticString for &'static str
Source§impl StaticString for Cow<'static, str>
Available on crate feature alloc only.
impl StaticString for Cow<'static, str>
Available on crate feature
alloc only.Source§impl StaticString for String
Available on crate feature alloc only.
impl StaticString for String
Available on crate feature
alloc only.