pub struct LimitedStr<'a, const N: usize = 1024>(/* private fields */);Expand description
Implementations§
Source§impl<'a, const N: usize> LimitedStr<'a, N>
impl<'a, const N: usize> LimitedStr<'a, N>
Sourcepub fn from_utf8(vec: LimitedVec<u8, N>) -> Result<Self, FromUtf8Error>
pub fn from_utf8(vec: LimitedVec<u8, N>) -> Result<Self, FromUtf8Error>
Constructs a limited string from a limited vector of bytes of the same size.
Sourcepub fn try_new<S: Into<Cow<'a, str>>>(s: S) -> Result<Self, LimitedStrError>
pub fn try_new<S: Into<Cow<'a, str>>>(s: S) -> Result<Self, LimitedStrError>
Constructs a limited string from a string.
Checks the size of the string.
Sourcepub fn truncated<S: Into<Cow<'a, str>>>(s: S) -> Self
pub fn truncated<S: Into<Cow<'a, str>>>(s: S) -> Self
Constructs a limited string from a string truncating it if it’s too long.
Sourcepub const fn from_small_str(s: &'static str) -> Self
pub const fn from_small_str(s: &'static str) -> Self
Constructs a limited string from a static string literal small enough to fit the limit.
Should be used only with static string literals. In that case it can check the string length in compile time.
§Panics
Can panic in runtime if the passed string is not a static string literal and is too long.
Sourcepub fn into_inner(self) -> Cow<'a, str>
pub fn into_inner(self) -> Cow<'a, str>
Return inner value.
Trait Implementations§
Source§impl<'a, const N: usize> Clone for LimitedStr<'a, N>
impl<'a, const N: usize> Clone for LimitedStr<'a, N>
Source§fn clone(&self) -> LimitedStr<'a, N>
fn clone(&self) -> LimitedStr<'a, N>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<'a, const N: usize> Debug for LimitedStr<'a, N>
impl<'a, const N: usize> Debug for LimitedStr<'a, N>
Source§impl<'a, const N: usize> Decode for LimitedStr<'a, N>
impl<'a, const N: usize> Decode for LimitedStr<'a, N>
Source§fn decode<I: Input>(input: &mut I) -> Result<Self, Error>
fn decode<I: Input>(input: &mut I) -> Result<Self, Error>
Attempt to deserialise the value from input.
Source§fn decode_into<I>(
input: &mut I,
dst: &mut MaybeUninit<Self>,
) -> Result<DecodeFinished, Error>where
I: Input,
fn decode_into<I>(
input: &mut I,
dst: &mut MaybeUninit<Self>,
) -> Result<DecodeFinished, Error>where
I: Input,
Attempt to deserialize the value from input into a pre-allocated piece of memory. Read more
Source§impl<'a, const N: usize> Default for LimitedStr<'a, N>
impl<'a, const N: usize> Default for LimitedStr<'a, N>
Source§fn default() -> LimitedStr<'a, N>
fn default() -> LimitedStr<'a, N>
Returns the “default value” for a type. Read more
Source§impl<'a, const N: usize> Deref for LimitedStr<'a, N>
impl<'a, const N: usize> Deref for LimitedStr<'a, N>
Source§impl<'a, const N: usize> Display for LimitedStr<'a, N>
impl<'a, const N: usize> Display for LimitedStr<'a, N>
Source§impl<'a, const N: usize> Encode for LimitedStr<'a, N>
impl<'a, const N: usize> Encode for LimitedStr<'a, N>
Source§fn size_hint(&self) -> usize
fn size_hint(&self) -> usize
If possible give a hint of expected size of the encoding. Read more
Source§fn encode_to<__CodecOutputEdqy: Output + ?Sized>(
&self,
__codec_dest_edqy: &mut __CodecOutputEdqy,
)
fn encode_to<__CodecOutputEdqy: Output + ?Sized>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy, )
Convert self to a slice and append it to the destination.
Source§fn using_encoded<__CodecOutputReturn, __CodecUsingEncodedCallback: FnOnce(&[u8]) -> __CodecOutputReturn>(
&self,
f: __CodecUsingEncodedCallback,
) -> __CodecOutputReturn
fn using_encoded<__CodecOutputReturn, __CodecUsingEncodedCallback: FnOnce(&[u8]) -> __CodecOutputReturn>( &self, f: __CodecUsingEncodedCallback, ) -> __CodecOutputReturn
Convert self to a slice and then invoke the given closure with it.
Source§fn encoded_size(&self) -> usize
fn encoded_size(&self) -> usize
Calculates the encoded size. Read more
Source§impl<'a, const N: usize> EncodeAsFields for LimitedStr<'a, N>
impl<'a, const N: usize> EncodeAsFields for LimitedStr<'a, N>
Source§fn encode_as_fields_to<ScaleEncodeResolver: TypeResolver>(
&self,
__encode_as_type_fields: &mut dyn FieldIter<'_, ScaleEncodeResolver::TypeId>,
__encode_as_type_types: &ScaleEncodeResolver,
__encode_as_type_out: &mut Vec<u8>,
) -> Result<(), Error>
fn encode_as_fields_to<ScaleEncodeResolver: TypeResolver>( &self, __encode_as_type_fields: &mut dyn FieldIter<'_, ScaleEncodeResolver::TypeId>, __encode_as_type_types: &ScaleEncodeResolver, __encode_as_type_out: &mut Vec<u8>, ) -> Result<(), Error>
Given some fields describing the shape of a type, attempt to encode to that shape.
Source§fn encode_as_fields<R>(
&self,
fields: &mut dyn FieldIter<'_, <R as TypeResolver>::TypeId, Item = Field<'_, <R as TypeResolver>::TypeId>>,
types: &R,
) -> Result<Vec<u8>, Error>where
R: TypeResolver,
fn encode_as_fields<R>(
&self,
fields: &mut dyn FieldIter<'_, <R as TypeResolver>::TypeId, Item = Field<'_, <R as TypeResolver>::TypeId>>,
types: &R,
) -> Result<Vec<u8>, Error>where
R: TypeResolver,
This is a helper function which internally calls
EncodeAsFields::encode_as_fields_to. Prefer to
implement that instead.Source§impl<'a, const N: usize> EncodeAsType for LimitedStr<'a, N>
impl<'a, const N: usize> EncodeAsType for LimitedStr<'a, N>
Source§fn encode_as_type_to<ScaleEncodeResolver: TypeResolver>(
&self,
__encode_as_type_type_id: ScaleEncodeResolver::TypeId,
__encode_as_type_types: &ScaleEncodeResolver,
__encode_as_type_out: &mut Vec<u8>,
) -> Result<(), Error>
fn encode_as_type_to<ScaleEncodeResolver: TypeResolver>( &self, __encode_as_type_type_id: ScaleEncodeResolver::TypeId, __encode_as_type_types: &ScaleEncodeResolver, __encode_as_type_out: &mut Vec<u8>, ) -> Result<(), Error>
Given some
type_id, types, a context and some output target for the SCALE encoded bytes,
attempt to SCALE encode the current value into the type given by type_id.Source§fn encode_as_type<R>(
&self,
type_id: <R as TypeResolver>::TypeId,
types: &R,
) -> Result<Vec<u8>, Error>where
R: TypeResolver,
fn encode_as_type<R>(
&self,
type_id: <R as TypeResolver>::TypeId,
types: &R,
) -> Result<Vec<u8>, Error>where
R: TypeResolver,
This is a helper function which internally calls
EncodeAsType::encode_as_type_to. Prefer to
implement that instead.impl<'a, const N: usize> EncodeLike for LimitedStr<'a, N>
impl<'a, const N: usize> Eq for LimitedStr<'a, N>
Source§impl From<LimitedStr<'_>> for PanicBuffer
impl From<LimitedStr<'_>> for PanicBuffer
Source§fn from(value: LimitedStr<'_>) -> Self
fn from(value: LimitedStr<'_>) -> Self
Converts to this type from the input type.
Source§impl<'a, const N: usize> From<LimitedStr<'a, N>> for Cow<'a, str>
impl<'a, const N: usize> From<LimitedStr<'a, N>> for Cow<'a, str>
Source§fn from(value: LimitedStr<'a, N>) -> Self
fn from(value: LimitedStr<'a, N>) -> Self
Converts to this type from the input type.
Source§impl<'a, const N: usize> Hash for LimitedStr<'a, N>
impl<'a, const N: usize> Hash for LimitedStr<'a, N>
Source§impl<'a, const N: usize> Ord for LimitedStr<'a, N>
impl<'a, const N: usize> Ord for LimitedStr<'a, N>
Source§fn cmp(&self, other: &LimitedStr<'a, N>) -> Ordering
fn cmp(&self, other: &LimitedStr<'a, N>) -> Ordering
1.21.0 (const: unstable) · 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<'a, const N: usize> PartialEq for LimitedStr<'a, N>
impl<'a, const N: usize> PartialEq for LimitedStr<'a, N>
Source§fn eq(&self, other: &LimitedStr<'a, N>) -> bool
fn eq(&self, other: &LimitedStr<'a, N>) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl<'a, const N: usize> PartialOrd for LimitedStr<'a, N>
impl<'a, const N: usize> PartialOrd for LimitedStr<'a, N>
impl<'a, const N: usize> StructuralPartialEq for LimitedStr<'a, N>
Auto Trait Implementations§
impl<'a, const N: usize> Freeze for LimitedStr<'a, N>
impl<'a, const N: usize> RefUnwindSafe for LimitedStr<'a, N>
impl<'a, const N: usize> Send for LimitedStr<'a, N>
impl<'a, const N: usize> Sync for LimitedStr<'a, N>
impl<'a, const N: usize> Unpin for LimitedStr<'a, N>
impl<'a, const N: usize> UnsafeUnpin for LimitedStr<'a, N>
impl<'a, const N: usize> UnwindSafe for LimitedStr<'a, N>
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