Skip to main content

SizedSafeString

Struct SizedSafeString 

Source
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>

Source

pub fn as_str(&self) -> &str

Source

pub const fn max_len(&self) -> usize

A convenience method to get the maximum length of SafeString instance

Source

pub const fn new() -> Self

Return an empty SafeString. This method does not allocate

Source

pub fn len(&self) -> usize

Returns the length (not capacity or max_length) of the string in bytes

Source

pub fn is_empty(&self) -> bool

Returns true if the string is empty

Source

pub fn try_push(&mut self, c: char) -> Result<(), SchemaStringError>

Appends the given char`` to the end of this SizedSafeString` if possible.

Source

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> AsRef<[u8]> for SizedSafeString<MAX_LEN>

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<const MAX_LEN: usize> AsRef<str> for SizedSafeString<MAX_LEN>

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<const MAX_LEN: usize> BorshDeserialize for SizedSafeString<MAX_LEN>

Source§

fn deserialize_reader<R: Read>(reader: &mut R) -> Result<Self>

Source§

fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>

Deserializes this instance from a given slice of bytes. Updates the buffer to point at the remaining bytes.
Source§

fn try_from_slice(v: &[u8]) -> Result<Self, Error>

Deserialize this instance from a slice of bytes.
Source§

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>

Source§

fn serialize<__W: Write>(&self, writer: &mut __W) -> Result<(), Error>

Source§

impl<const MAX_LEN: usize> Clone for SizedSafeString<MAX_LEN>

Source§

fn clone(&self) -> SizedSafeString<MAX_LEN>

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<const MAX_LEN: usize> Debug for SizedSafeString<MAX_LEN>

Source§

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

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

impl<const MAX_LEN: usize> Default for SizedSafeString<MAX_LEN>

Source§

fn default() -> SizedSafeString<MAX_LEN>

Returns the “default value” for a type. Read more
Source§

impl<const MAX_LEN: usize> Display for SizedSafeString<MAX_LEN>

Source§

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

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

impl<const MAX_LEN: usize> From<SizedSafeString<MAX_LEN>> for String

Source§

fn from(value: SizedSafeString<MAX_LEN>) -> Self

Converts to this type from the input type.
Source§

impl<const MAX_LEN: usize> FromStr for SizedSafeString<MAX_LEN>

Source§

type Err = SchemaStringError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl<const MAX_LEN: usize> Hash for SizedSafeString<MAX_LEN>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<const MAX_LEN: usize> Ord for SizedSafeString<MAX_LEN>

Source§

fn cmp(&self, other: &SizedSafeString<MAX_LEN>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<const MAX_LEN: usize> PartialEq for SizedSafeString<MAX_LEN>

Source§

fn eq(&self, other: &SizedSafeString<MAX_LEN>) -> 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<const MAX_LEN: usize> PartialOrd for SizedSafeString<MAX_LEN>

Source§

fn partial_cmp(&self, other: &SizedSafeString<MAX_LEN>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a, const MAX_LEN: usize> TryFrom<&'a str> for SizedSafeString<MAX_LEN>

Source§

type Error = SchemaStringError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &'a str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<const MAX_LEN: usize> TryFrom<String> for SizedSafeString<MAX_LEN>

Source§

type Error = SchemaStringError

The type returned in the event of a conversion error.
Source§

fn try_from(value: String) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<const MAX_LEN: usize> UniversalWallet for SizedSafeString<MAX_LEN>

Source§

fn scaffold() -> Item<IndexLinking>

Generate the “scaffolding” of the item. If the item is a primtive, this is just the corresponding primtive. If the type is composed of other types, this is the container with all links set to Link::Placeholder.
Ensure that each type contained in the outer type (i.e. the type of each struct/tuple field) is added to the schema, and return a Link connecting the child to the parent. Read more
Source§

fn write_schema(schema: &mut Schema) -> Link

Writes the type to the schema if it is not already present and returns a link to it. Read more
Source§

fn make_root_of(schema: &mut Schema)

Writes the type and all its children to the schema, if not already present, and sets the type as a root type. Generates any templates defined on that type.
Source§

fn get_child_templates(_schema: &mut Schema) -> TransactionTemplateSet

Empty by default When derived by the macro, builds a template set from annotations on the fields + the field types’ own get_child_templates()
Source§

fn make_linkable(schema: &mut Schema) -> Link

Gets a link to the type, writing the type to the schema if necessary.
Source§

fn id_override() -> Option<ItemId>

Override the type ID of the item. This should typically not be written by hand. Instead, use the OverrideSchema trait.
Source§

impl<const MAX_LEN: usize> Eq for SizedSafeString<MAX_LEN>

Source§

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> 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> ToHex for T
where T: AsRef<[u8]>,

Source§

fn encode_hex<U>(&self) -> U
where U: FromIterator<char>,

Encode the hex strict representing self into the result. Lower case letters are used (e.g. f9b4ca)
Source§

fn encode_hex_upper<U>(&self) -> U
where U: FromIterator<char>,

Encode the hex strict representing self into the result. Upper case letters are used (e.g. F9B4CA)
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.