Struct soroban_sdk::BytesN
source · [−]#[repr(transparent)]pub struct BytesN<const N: usize>(_);
Expand description
BytesN is a contiguous fixed-size array type containing u8
s.
The array is stored in the Host and available to the Guest through the functions defined on Bytes.
Bytes values can be stored as ContractData, or in other types like Vec, Map, etc.
Examples
BytesN values can be created from arrays:
use soroban_sdk::{Bytes, BytesN, Env};
let env = Env::default();
let bytes = BytesN::from_array(&env, &[0; 32]);
assert_eq!(bytes.len(), 32);
BytesN and Bytes values are convertible:
use soroban_sdk::{Bytes, BytesN, Env};
let env = Env::default();
let bytes = Bytes::from_slice(&env, &[0; 32]);
let bytes: BytesN<32> = bytes.try_into().expect("bytes to have length 32");
assert_eq!(bytes.len(), 32);
Implementations
sourceimpl<const N: usize> BytesN<N>
impl<const N: usize> BytesN<N>
pub fn env(&self) -> &Env
pub fn as_raw(&self) -> &RawVal
pub fn to_raw(&self) -> RawVal
pub fn as_object(&self) -> &Object
pub fn to_object(&self) -> Object
pub fn from_array(env: &Env, items: &[u8; N]) -> BytesN<N>
pub fn set(&mut self, i: u32, v: u8)
pub fn get(&self, i: u32) -> Option<u8>
pub fn get_unchecked(&self, i: u32) -> u8
pub fn is_empty(&self) -> bool
pub fn len(&self) -> u32
pub fn first(&self) -> Option<u8>
pub fn first_unchecked(&self) -> u8
pub fn last(&self) -> Option<u8>
pub fn last_unchecked(&self) -> u8
sourcepub fn copy_into_slice(&self, slice: &mut [u8])
pub fn copy_into_slice(&self, slice: &mut [u8])
pub fn iter(&self) -> BinIter
Trait Implementations
sourceimpl<const N: usize> IntoIterator for BytesN<N>
impl<const N: usize> IntoIterator for BytesN<N>
sourceimpl<const N: usize> Ord for BytesN<N>
impl<const N: usize> Ord for BytesN<N>
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl<const N: usize> PartialEq<BytesN<N>> for BytesN<N>
impl<const N: usize> PartialEq<BytesN<N>> for BytesN<N>
sourceimpl<const N: usize> PartialOrd<BytesN<N>> for BytesN<N>
impl<const N: usize> PartialOrd<BytesN<N>> for BytesN<N>
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl<const N: usize> TryFromVal<Env, Object> for BytesN<N>
impl<const N: usize> TryFromVal<Env, Object> for BytesN<N>
type Error = ConversionError
fn try_from_val(env: &Env, val: Object) -> Result<Self, Self::Error>
sourceimpl<const N: usize> TryFromVal<Env, RawVal> for BytesN<N>
impl<const N: usize> TryFromVal<Env, RawVal> for BytesN<N>
type Error = ConversionError
fn try_from_val(env: &Env, val: RawVal) -> Result<Self, Self::Error>
sourceimpl<const N: usize> TryFromVal<Env, ScVal> for BytesN<N>
impl<const N: usize> TryFromVal<Env, ScVal> for BytesN<N>
type Error = ConversionError
fn try_from_val(env: &Env, val: ScVal) -> Result<Self, Self::Error>
sourceimpl<const N: usize> TryIntoVal<Env, BytesN<N>> for Object
impl<const N: usize> TryIntoVal<Env, BytesN<N>> for Object
type Error = ConversionError
fn try_into_val(self, env: &Env) -> Result<BytesN<N>, Self::Error>
fn try_into_env_val(self, env: &E) -> Result<EnvVal<E, V>, Self::Error>
sourceimpl<const N: usize> TryIntoVal<Env, BytesN<N>> for RawVal
impl<const N: usize> TryIntoVal<Env, BytesN<N>> for RawVal
type Error = ConversionError
fn try_into_val(self, env: &Env) -> Result<BytesN<N>, Self::Error>
fn try_into_env_val(self, env: &E) -> Result<EnvVal<E, V>, Self::Error>
sourceimpl<const N: usize> TryIntoVal<Env, BytesN<N>> for ScVal
impl<const N: usize> TryIntoVal<Env, BytesN<N>> for ScVal
type Error = ConversionError
fn try_into_val(self, env: &Env) -> Result<BytesN<N>, Self::Error>
fn try_into_env_val(self, env: &E) -> Result<EnvVal<E, V>, Self::Error>
impl<const N: usize> Eq for BytesN<N>
Auto Trait Implementations
impl<const N: usize> !RefUnwindSafe for BytesN<N>
impl<const N: usize> !Send for BytesN<N>
impl<const N: usize> !Sync for BytesN<N>
impl<const N: usize> Unpin for BytesN<N>
impl<const N: usize> !UnwindSafe for BytesN<N>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Deserialize for T where
T: TryFromVal<Env, RawVal>,
impl<T> Deserialize for T where
T: TryFromVal<Env, RawVal>,
type Error = <T as TryFromVal<Env, RawVal>>::Error
fn deserialize(env: &Env, b: &Bytes) -> Result<T, <T as Deserialize>::Error>
impl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Convert Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
. Read more
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert &mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read more