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 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 · 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<__CodecInputEdqy: Input>(
__codec_input_edqy: &mut __CodecInputEdqy,
) -> Result<Self, Error>
fn decode<__CodecInputEdqy: Input>( __codec_input_edqy: &mut __CodecInputEdqy, ) -> 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> DecodeAsFields for LimitedStr<'a, N>
impl<'a, const N: usize> DecodeAsFields for LimitedStr<'a, N>
Source§fn decode_as_fields<'info, R: TypeResolver>(
input: &mut &[u8],
fields: &mut dyn FieldIter<'info, R::TypeId>,
types: &'info R,
) -> Result<Self, Error>
fn decode_as_fields<'info, R: TypeResolver>( input: &mut &[u8], fields: &mut dyn FieldIter<'info, R::TypeId>, types: &'info R, ) -> Result<Self, Error>
Given some bytes and some fields denoting their structure, attempt to decode.
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.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> IntoVisitor for LimitedStr<'a, N>
impl<'a, const N: usize> IntoVisitor for LimitedStr<'a, N>
Source§type AnyVisitor<ScaleDecodeTypeResolver: TypeResolver> = Visitor<'a, N, ScaleDecodeTypeResolver>
type AnyVisitor<ScaleDecodeTypeResolver: TypeResolver> = Visitor<'a, N, ScaleDecodeTypeResolver>
The visitor type used to decode SCALE encoded bytes to
Self.Source§fn into_visitor<ScaleDecodeTypeResolver: TypeResolver>() -> Self::AnyVisitor<ScaleDecodeTypeResolver>
fn into_visitor<ScaleDecodeTypeResolver: TypeResolver>() -> Self::AnyVisitor<ScaleDecodeTypeResolver>
A means of obtaining this visitor.
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 · 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§impl<'a, const N: usize> PartialOrd for LimitedStr<'a, N>
impl<'a, const N: usize> PartialOrd for LimitedStr<'a, N>
Source§impl<'a> TryFrom<&'a str> for LimitedStr<'a>
impl<'a> TryFrom<&'a str> for LimitedStr<'a>
Source§impl<'a> TryFrom<String> for LimitedStr<'a>
impl<'a> TryFrom<String> for LimitedStr<'a>
Source§impl<'a, const N: usize> TypeInfo for LimitedStr<'a, N>where
'a: 'static,
impl<'a, const N: usize> TypeInfo for LimitedStr<'a, N>where
'a: 'static,
impl<'a, const N: usize> EncodeLike for LimitedStr<'a, N>
impl<'a, const N: usize> Eq 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> 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DecodeAsType for Twhere
T: IntoVisitor,
impl<T> DecodeAsType for Twhere
T: IntoVisitor,
fn decode_as_type_maybe_compact<R>(
input: &mut &[u8],
type_id: <R as TypeResolver>::TypeId,
types: &R,
is_compact: bool,
) -> Result<T, Error>where
R: TypeResolver,
Source§fn decode_as_type<R>(
input: &mut &[u8],
type_id: <R as TypeResolver>::TypeId,
types: &R,
) -> Result<Self, Error>where
R: TypeResolver,
fn decode_as_type<R>(
input: &mut &[u8],
type_id: <R as TypeResolver>::TypeId,
types: &R,
) -> Result<Self, Error>where
R: TypeResolver,
Given some input bytes, a
type_id, and type registry, attempt to decode said bytes into
Self. Implementations should modify the &mut reference to the bytes such that any bytes
not used in the course of decoding are still pointed to after decoding is complete.