pub struct BoundedString<const N: usize> { /* private fields */ }Expand description
Bounded UTF-8 string for Hopper dynamic tails.
This is the common migration target for bounded string account metadata.
It keeps a fixed [u8; N] backing buffer, carries a small length prefix on
the tail wire, and validates UTF-8 when read as &str.
Implementations§
Source§impl<const N: usize> BoundedString<N>
impl<const N: usize> BoundedString<N>
Sourcepub const fn empty() -> BoundedString<N>
pub const fn empty() -> BoundedString<N>
Construct an empty bounded string.
Sourcepub fn from_str(value: &str) -> Result<BoundedString<N>, ProgramError>
pub fn from_str(value: &str) -> Result<BoundedString<N>, ProgramError>
Construct from UTF-8 bytes, rejecting values longer than N.
Sourcepub fn from_bytes(value: &[u8]) -> Result<BoundedString<N>, ProgramError>
pub fn from_bytes(value: &[u8]) -> Result<BoundedString<N>, ProgramError>
Construct from bytes, rejecting values longer than N.
Sourcepub fn set_str(&mut self, value: &str) -> Result<(), ProgramError>
pub fn set_str(&mut self, value: &str) -> Result<(), ProgramError>
Replace the contents in place.
Sourcepub fn set_bytes(&mut self, value: &[u8]) -> Result<(), ProgramError>
pub fn set_bytes(&mut self, value: &[u8]) -> Result<(), ProgramError>
Replace the contents in place.
Sourcepub fn as_str(&self) -> Result<&str, ProgramError>
pub fn as_str(&self) -> Result<&str, ProgramError>
Return the initialized bytes as UTF-8.
Sourcepub const fn remaining_capacity(&self) -> usize
pub const fn remaining_capacity(&self) -> usize
Remaining byte capacity.
Trait Implementations§
Source§impl<const N: usize> Clone for BoundedString<N>
impl<const N: usize> Clone for BoundedString<N>
Source§fn clone(&self) -> BoundedString<N>
fn clone(&self) -> BoundedString<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<const N: usize> Default for BoundedString<N>
impl<const N: usize> Default for BoundedString<N>
Source§fn default() -> BoundedString<N>
fn default() -> BoundedString<N>
Returns the “default value” for a type. Read more
Source§impl<const N: usize> PartialEq for BoundedString<N>
impl<const N: usize> PartialEq for BoundedString<N>
Source§fn eq(&self, other: &BoundedString<N>) -> bool
fn eq(&self, other: &BoundedString<N>) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl<const N: usize> TailCodec for BoundedString<N>
impl<const N: usize> TailCodec for BoundedString<N>
Source§const MAX_ENCODED_LEN: usize
const MAX_ENCODED_LEN: usize
Upper bound on the encoded size. Used by generated helpers to
verify the account has enough room before invoking
encode.
Implementors should pick the smallest valid bound. Hopper
uses this to pre-size reallocs.Source§fn encode(&self, out: &mut [u8]) -> Result<usize, ProgramError>
fn encode(&self, out: &mut [u8]) -> Result<usize, ProgramError>
Serialize
self into out. Returns the number of bytes
written (always <= MAX_ENCODED_LEN). Fails with
AccountDataTooSmall when out.len() < encoded_len.Source§fn decode(input: &[u8]) -> Result<(BoundedString<N>, usize), ProgramError>
fn decode(input: &[u8]) -> Result<(BoundedString<N>, usize), ProgramError>
Deserialize from
input. Returns (value, bytes_consumed).
Fails with InvalidAccountData on malformed encoding.impl<const N: usize> Copy for BoundedString<N>
impl<const N: usize> Eq for BoundedString<N>
impl<const N: usize> StructuralPartialEq for BoundedString<N>
Auto Trait Implementations§
impl<const N: usize> Freeze for BoundedString<N>
impl<const N: usize> RefUnwindSafe for BoundedString<N>
impl<const N: usize> Send for BoundedString<N>
impl<const N: usize> Sync for BoundedString<N>
impl<const N: usize> Unpin for BoundedString<N>
impl<const N: usize> UnsafeUnpin for BoundedString<N>
impl<const N: usize> UnwindSafe for BoundedString<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