ManagedString

Enum ManagedString 

Source
pub enum ManagedString<'a, T>
where T: ArrayLength<u8>,
{ Owned(String<T>), Borrow(&'a str), }
Expand description

A borrowed or owned string

Basically like CoW, but with heapless::String

Variants§

§

Owned(String<T>)

§

Borrow(&'a str)

Implementations§

Source§

impl<'a, T> ManagedString<'a, T>
where T: ArrayLength<u8>,

Source

pub fn as_str(&self) -> &str

Obtain self as a string slice

Source

pub fn as_borrowed(&'a self) -> ManagedString<'a, T>

Retrieve a borrowed copy of the string

Source

pub fn try_from_str(input: &str) -> Result<ManagedString<'static, T>, ()>

Attempt to create an Owned string from a given str

May fail if the heapless::String is not large enough to contain this slice

Source

pub fn borrow_from_str(input: &str) -> ManagedString<'_, T>

Create a Borrowed string from a given str

Source

pub fn try_to_owned(&self) -> Result<ManagedString<'static, T>, ()>

Attempt to convert to an Owned string from the current state

May fail if the heapless::String is not large enough to contain this slice

Trait Implementations§

Source§

impl<'a, T> Clone for ManagedString<'a, T>
where T: Clone + ArrayLength<u8>,

Source§

fn clone(&self) -> ManagedString<'a, T>

Returns a duplicate 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<'a, T> Debug for ManagedString<'a, T>
where T: Debug + ArrayLength<u8>,

Source§

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

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

impl<'a, 'de, T> Deserialize<'de> for ManagedString<'a, T>
where 'de: 'a, T: ArrayLength<u8>,

Source§

fn deserialize<D>( deserializer: D, ) -> Result<ManagedString<'a, T>, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

We can deserialize as a borrowed str

Source§

impl<'a, T> PartialEq for ManagedString<'a, T>
where T: PartialEq + ArrayLength<u8>,

Source§

fn eq(&self, other: &ManagedString<'a, T>) -> 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, T> Serialize for ManagedString<'a, T>
where T: ArrayLength<u8>,

Source§

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

We can serialize our managed string as a str

Source§

impl<'a, T> Eq for ManagedString<'a, T>
where T: Eq + ArrayLength<u8>,

Source§

impl<'a, T> StructuralPartialEq for ManagedString<'a, T>
where T: ArrayLength<u8>,

Auto Trait Implementations§

§

impl<'a, T> Freeze for ManagedString<'a, T>
where <T as ArrayLength<u8>>::ArrayType: Freeze,

§

impl<'a, T> RefUnwindSafe for ManagedString<'a, T>

§

impl<'a, T> Send for ManagedString<'a, T>

§

impl<'a, T> Sync for ManagedString<'a, T>

§

impl<'a, T> Unpin for ManagedString<'a, T>
where <T as ArrayLength<u8>>::ArrayType: Unpin,

§

impl<'a, T> UnwindSafe for ManagedString<'a, T>

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,