pub struct SizedSafeString<const MAX_LEN: usize>(/* private fields */);Expand description
A String wrapper which enforces certain constraints to ensure it is safely displayable as part of a transaction without confusing the user. Only printable ASCII is allowed, and the length is limited.
UniversalWallet implementation is forbidden on std::String by default, to avoid the possibility
of untrusted input supplying highly confusing text that tricks users into misunderstanding the
transaction they are signing. SafeString enforces some constraints to mitigate this risk. If
you need to encode a large data blob such as a hex string, use a Vec<u8> with the
[sov_wallet(display = "hex")] attribute (or any of the other display styles). Avoid raw
Strings if possible.
If an actual String is absolutely necessary, then a newtype wrapper can be used, on which
UniversalWallet is derived manually.
Implementations§
Source§impl<const MAX_LEN: usize> SizedSafeString<MAX_LEN>
impl<const MAX_LEN: usize> SizedSafeString<MAX_LEN>
pub fn as_str(&self) -> &str
Sourcepub const fn max_len(&self) -> usize
pub const fn max_len(&self) -> usize
A convenience method to get the maximum length of SafeString instance
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the length (not capacity or max_length) of the string in bytes
Sourcepub fn try_push(&mut self, c: char) -> Result<(), SchemaStringError>
pub fn try_push(&mut self, c: char) -> Result<(), SchemaStringError>
Appends the given char`` to the end of this SizedSafeString` if possible.
Sourcepub const fn is_valid_char(c: char) -> bool
pub const fn is_valid_char(c: char) -> bool
Returns true if the character is a valid member of SizedSafeString
Trait Implementations§
Source§impl<const MAX_LEN: usize> BorshDeserialize for SizedSafeString<MAX_LEN>
impl<const MAX_LEN: usize> BorshDeserialize for SizedSafeString<MAX_LEN>
fn deserialize_reader<R: Read>(reader: &mut R) -> Result<Self>
Source§fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
Source§fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>where
R: Read,
Source§impl<const MAX_LEN: usize> BorshSerialize for SizedSafeString<MAX_LEN>
impl<const MAX_LEN: usize> BorshSerialize for SizedSafeString<MAX_LEN>
Source§impl<const MAX_LEN: usize> Clone for SizedSafeString<MAX_LEN>
impl<const MAX_LEN: usize> Clone for SizedSafeString<MAX_LEN>
Source§fn clone(&self) -> SizedSafeString<MAX_LEN>
fn clone(&self) -> SizedSafeString<MAX_LEN>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<const MAX_LEN: usize> Debug for SizedSafeString<MAX_LEN>
impl<const MAX_LEN: usize> Debug for SizedSafeString<MAX_LEN>
Source§impl<const MAX_LEN: usize> Default for SizedSafeString<MAX_LEN>
impl<const MAX_LEN: usize> Default for SizedSafeString<MAX_LEN>
Source§fn default() -> SizedSafeString<MAX_LEN>
fn default() -> SizedSafeString<MAX_LEN>
Source§impl<const MAX_LEN: usize> Display for SizedSafeString<MAX_LEN>
impl<const MAX_LEN: usize> Display for SizedSafeString<MAX_LEN>
Source§impl<const MAX_LEN: usize> From<SizedSafeString<MAX_LEN>> for String
impl<const MAX_LEN: usize> From<SizedSafeString<MAX_LEN>> for String
Source§fn from(value: SizedSafeString<MAX_LEN>) -> Self
fn from(value: SizedSafeString<MAX_LEN>) -> Self
Source§impl<const MAX_LEN: usize> FromStr for SizedSafeString<MAX_LEN>
impl<const MAX_LEN: usize> FromStr for SizedSafeString<MAX_LEN>
Source§impl<const MAX_LEN: usize> Hash for SizedSafeString<MAX_LEN>
impl<const MAX_LEN: usize> Hash for SizedSafeString<MAX_LEN>
Source§impl<const MAX_LEN: usize> Ord for SizedSafeString<MAX_LEN>
impl<const MAX_LEN: usize> Ord for SizedSafeString<MAX_LEN>
Source§fn cmp(&self, other: &SizedSafeString<MAX_LEN>) -> Ordering
fn cmp(&self, other: &SizedSafeString<MAX_LEN>) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<const MAX_LEN: usize> PartialEq for SizedSafeString<MAX_LEN>
impl<const MAX_LEN: usize> PartialEq for SizedSafeString<MAX_LEN>
Source§impl<const MAX_LEN: usize> PartialOrd for SizedSafeString<MAX_LEN>
impl<const MAX_LEN: usize> PartialOrd for SizedSafeString<MAX_LEN>
Source§impl<const MAX_LEN: usize> UniversalWallet for SizedSafeString<MAX_LEN>
impl<const MAX_LEN: usize> UniversalWallet for SizedSafeString<MAX_LEN>
Source§fn scaffold() -> Item<IndexLinking>
fn scaffold() -> Item<IndexLinking>
Link::Placeholder.Source§fn get_child_links(_schema: &mut Schema) -> Vec<Link>
fn get_child_links(_schema: &mut Schema) -> Vec<Link>
Link connecting the child to the parent. Read moreSource§fn write_schema(schema: &mut Schema) -> Link
fn write_schema(schema: &mut Schema) -> Link
Source§fn make_root_of(schema: &mut Schema)
fn make_root_of(schema: &mut Schema)
Source§fn get_child_templates(_schema: &mut Schema) -> TransactionTemplateSet
fn get_child_templates(_schema: &mut Schema) -> TransactionTemplateSet
Source§fn make_linkable(schema: &mut Schema) -> Link
fn make_linkable(schema: &mut Schema) -> Link
Source§fn id_override() -> Option<ItemId>
fn id_override() -> Option<ItemId>
OverrideSchema trait.impl<const MAX_LEN: usize> Eq for SizedSafeString<MAX_LEN>
impl<const MAX_LEN: usize> StructuralPartialEq for SizedSafeString<MAX_LEN>
Auto Trait Implementations§
impl<const MAX_LEN: usize> Freeze for SizedSafeString<MAX_LEN>
impl<const MAX_LEN: usize> RefUnwindSafe for SizedSafeString<MAX_LEN>
impl<const MAX_LEN: usize> Send for SizedSafeString<MAX_LEN>
impl<const MAX_LEN: usize> Sync for SizedSafeString<MAX_LEN>
impl<const MAX_LEN: usize> Unpin for SizedSafeString<MAX_LEN>
impl<const MAX_LEN: usize> UnsafeUnpin for SizedSafeString<MAX_LEN>
impl<const MAX_LEN: usize> UnwindSafe for SizedSafeString<MAX_LEN>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ToHex for T
impl<T> ToHex for T
Source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
self into the result. Lower case
letters are used (e.g. f9b4ca)Source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
self into the result. Upper case
letters are used (e.g. F9B4CA)