#[repr(transparent)]pub struct StorableStr(pub Cow<'static, str>);
Expand description
A Storable
string.
This is a wrapper around a Cow<'static, str>
that can be stored in the database.
§Invariant
StorableStr::from_bytes
will panic
if the bytes are not UTF-8. This should normally
not be possible in database operations, although technically
you can call this function yourself and input bad data.
§Example
let string: StorableStr = StorableStr(Cow::Borrowed("a"));
// Into bytes.
let into = Storable::as_bytes(&string);
assert_eq!(into, &[97]);
// From bytes.
let from: StorableStr = Storable::from_bytes(&into);
assert_eq!(from, string);
Tuple Fields§
§0: Cow<'static, str>
Methods from Deref<Target = Cow<'static, str>>§
Sourcepub fn is_borrowed(&self) -> bool
🔬This is a nightly-only experimental API. (cow_is_borrowed
)
pub fn is_borrowed(&self) -> bool
cow_is_borrowed
)Returns true if the data is borrowed, i.e. if to_mut
would require additional work.
§Examples
#![feature(cow_is_borrowed)]
use std::borrow::Cow;
let cow = Cow::Borrowed("moo");
assert!(cow.is_borrowed());
let bull: Cow<'_, str> = Cow::Owned("...moo?".to_string());
assert!(!bull.is_borrowed());
Sourcepub fn is_owned(&self) -> bool
🔬This is a nightly-only experimental API. (cow_is_borrowed
)
pub fn is_owned(&self) -> bool
cow_is_borrowed
)Returns true if the data is owned, i.e. if to_mut
would be a no-op.
§Examples
#![feature(cow_is_borrowed)]
use std::borrow::Cow;
let cow: Cow<'_, str> = Cow::Owned("moo".to_string());
assert!(cow.is_owned());
let bull = Cow::Borrowed("...moo?");
assert!(!bull.is_owned());
Trait Implementations§
Source§impl Clone for StorableStr
impl Clone for StorableStr
Source§fn clone(&self) -> StorableStr
fn clone(&self) -> StorableStr
Returns a copy 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 Debug for StorableStr
impl Debug for StorableStr
Source§impl Deref for StorableStr
impl Deref for StorableStr
Source§impl Hash for StorableStr
impl Hash for StorableStr
Source§impl Key for StorableStr
impl Key for StorableStr
Source§const KEY_COMPARE: KeyCompare = KeyCompare::Default
const KEY_COMPARE: KeyCompare = KeyCompare::Default
Source§impl Ord for StorableStr
impl Ord for StorableStr
Source§fn cmp(&self, other: &StorableStr) -> Ordering
fn cmp(&self, other: &StorableStr) -> 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 PartialEq for StorableStr
impl PartialEq for StorableStr
Source§impl PartialOrd for StorableStr
impl PartialOrd for StorableStr
Source§impl Storable for StorableStr
impl Storable for StorableStr
Source§impl TransparentWrapper<Cow<'static, str>> for StorableStr
impl TransparentWrapper<Cow<'static, str>> for StorableStr
Source§fn wrap_ref(s: &Inner) -> &Self
fn wrap_ref(s: &Inner) -> &Self
Convert a reference to the inner type into a reference to the wrapper
type.
Source§fn wrap_mut(s: &mut Inner) -> &mut Self
fn wrap_mut(s: &mut Inner) -> &mut Self
Convert a mutable reference to the inner type into a mutable reference to
the wrapper type.
Source§fn wrap_slice(s: &[Inner]) -> &[Self]where
Self: Sized,
fn wrap_slice(s: &[Inner]) -> &[Self]where
Self: Sized,
Convert a slice to the inner type into a slice to the wrapper type.
Source§fn wrap_slice_mut(s: &mut [Inner]) -> &mut [Self]where
Self: Sized,
fn wrap_slice_mut(s: &mut [Inner]) -> &mut [Self]where
Self: Sized,
Convert a mutable slice to the inner type into a mutable slice to the
wrapper type.
Source§fn peel_ref(s: &Self) -> &Inner
fn peel_ref(s: &Self) -> &Inner
Convert a reference to the wrapper type into a reference to the inner
type.
Source§fn peel_mut(s: &mut Self) -> &mut Inner
fn peel_mut(s: &mut Self) -> &mut Inner
Convert a mutable reference to the wrapper type into a mutable reference
to the inner type.
Source§fn peel_slice(s: &[Self]) -> &[Inner]where
Self: Sized,
fn peel_slice(s: &[Self]) -> &[Inner]where
Self: Sized,
Convert a slice to the wrapped type into a slice to the inner type.
Source§fn peel_slice_mut(s: &mut [Self]) -> &mut [Inner]where
Self: Sized,
fn peel_slice_mut(s: &mut [Self]) -> &mut [Inner]where
Self: Sized,
Convert a mutable slice to the wrapped type into a mutable slice to the
inner type.
impl Eq for StorableStr
impl StructuralPartialEq for StorableStr
Auto Trait Implementations§
impl Freeze for StorableStr
impl RefUnwindSafe for StorableStr
impl Send for StorableStr
impl Sync for StorableStr
impl Unpin for StorableStr
impl UnwindSafe for StorableStr
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<I, T> TransparentWrapperAlloc<I> for T
impl<I, T> TransparentWrapperAlloc<I> for T
Source§fn wrap_vec(s: Vec<Inner>) -> Vec<Self>where
Self: Sized,
fn wrap_vec(s: Vec<Inner>) -> Vec<Self>where
Self: Sized,
Convert a vec of the inner type into a vec of the wrapper type.
Source§fn wrap_box(s: Box<Inner>) -> Box<Self>
fn wrap_box(s: Box<Inner>) -> Box<Self>
Convert a box to the inner type into a box to the wrapper
type.
Source§fn wrap_rc(s: Rc<Inner>) -> Rc<Self>
fn wrap_rc(s: Rc<Inner>) -> Rc<Self>
Convert an
Rc
to the inner type into an Rc
to the wrapper type.Source§fn wrap_arc(s: Arc<Inner>) -> Arc<Self>
fn wrap_arc(s: Arc<Inner>) -> Arc<Self>
Convert an
Arc
to the inner type into an Arc
to the wrapper type.Source§fn peel_vec(s: Vec<Self>) -> Vec<Inner>where
Self: Sized,
fn peel_vec(s: Vec<Self>) -> Vec<Inner>where
Self: Sized,
Convert a vec of the wrapper type into a vec of the inner type.
Source§fn peel_box(s: Box<Self>) -> Box<Inner>
fn peel_box(s: Box<Self>) -> Box<Inner>
Convert a box to the wrapper type into a box to the inner
type.
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 24 bytes