soroban_sdk

Struct BytesN

Source
pub struct BytesN<const N: usize>(/* private fields */);
Expand description

BytesN is a contiguous fixed-size array type containing u8s.

The array is stored in the Host and available to the Guest through the functions defined on Bytes.

Bytes values can be stored as Storage, 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§

Source§

impl<const N: usize> BytesN<N>

Source

pub fn env(&self) -> &Env

Source

pub fn as_val(&self) -> &Val

Source

pub fn to_val(&self) -> Val

Source

pub fn as_object(&self) -> &BytesObject

Source

pub fn to_object(&self) -> BytesObject

Source

pub fn from_array(env: &Env, items: &[u8; N]) -> BytesN<N>

Create a BytesN from the slice.

Source

pub fn set(&mut self, i: u32, v: u8)

Sets the byte at the position with new value.

§Panics

If the position is out-of-bounds.

Source

pub fn get(&self, i: u32) -> Option<u8>

Returns the byte at the position or None if out-of-bounds.

Source

pub fn get_unchecked(&self, i: u32) -> u8

Returns the byte at the position.

§Panics

If the position is out-of-bounds.

Source

pub fn is_empty(&self) -> bool

Returns true if the Bytes is empty and has a length of zero.

Source

pub fn len(&self) -> u32

Returns the number of bytes are in the Bytes.

Source

pub fn first(&self) -> Option<u8>

Returns the first byte or None if empty.

Source

pub fn first_unchecked(&self) -> u8

Returns the first byte.

§Panics

If the Bytes is empty.

Source

pub fn last(&self) -> Option<u8>

Returns the last byte or None if empty.

Source

pub fn last_unchecked(&self) -> u8

Returns the last byte.

§Panics

If the Bytes is empty.

Source

pub fn copy_into_slice(&self, slice: &mut [u8; N])

Copy the bytes into the given slice.

Source

pub fn to_array(&self) -> [u8; N]

Copy the bytes in BytesN into an array.

Source

pub fn iter(&self) -> BytesIter

Trait Implementations§

Source§

impl<const N: usize> AsRef<Bytes> for BytesN<N>

Source§

fn as_ref(&self) -> &Bytes

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

impl<const N: usize> Borrow<Bytes> for &BytesN<N>

Source§

fn borrow(&self) -> &Bytes

Immutably borrows from an owned value. Read more
Source§

impl<const N: usize> Borrow<Bytes> for &mut BytesN<N>

Source§

fn borrow(&self) -> &Bytes

Immutably borrows from an owned value. Read more
Source§

impl<const N: usize> Borrow<Bytes> for BytesN<N>

Source§

fn borrow(&self) -> &Bytes

Immutably borrows from an owned value. Read more
Source§

impl<const N: usize> BytesN<N> for BytesN<N>

Available on crate feature testutils only.
Source§

fn random(env: &Env) -> BytesN<N>

Source§

impl<const N: usize> Clone for BytesN<N>

Source§

fn clone(&self) -> BytesN<N>

Returns a copy 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 N: usize> Debug for BytesN<N>

Source§

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

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

impl<const N: usize> Fill for BytesN<N>

Source§

fn fill(&mut self, prng: &Prng)

Fills the BytesN with the Prng.

§Panics

If the length of BytesN is greater than u32::MAX in length.

Source§

impl<const N: usize> From<&BytesN<N>> for [u8; N]

Source§

fn from(bin: &BytesN<N>) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> From<&BytesN<N>> for Bytes

Source§

fn from(v: &BytesN<N>) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> From<BytesN<N>> for [u8; N]

Source§

fn from(bin: BytesN<N>) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> From<BytesN<N>> for Bytes

Source§

fn from(v: BytesN<N>) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> From<BytesN<N>> for Val

Source§

fn from(v: BytesN<N>) -> Self

Converts to this type from the input type.
Source§

impl From<Fp> for BytesN<48>

Source§

fn from(v: Fp) -> Self

Converts to this type from the input type.
Source§

impl From<Fp2> for BytesN<96>

Source§

fn from(v: Fp2) -> Self

Converts to this type from the input type.
Source§

impl From<G1Affine> for BytesN<96>

Source§

fn from(v: G1Affine) -> Self

Converts to this type from the input type.
Source§

impl From<G2Affine> for BytesN<192>

Source§

fn from(v: G2Affine) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> From<Hash<N>> for BytesN<N>

Source§

fn from(v: Hash<N>) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> Gen for BytesN<N>

Source§

fn gen(prng: &Prng) -> Self

Generates the BytesN with the Prng.

§Panics

If the length of BytesN is greater than u32::MAX in length.

Source§

impl<const N: usize> IntoIterator for BytesN<N>

Source§

type Item = u8

The type of the elements being iterated over.
Source§

type IntoIter = BytesIter

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoVal<Env, BytesN<192>> for G2Affine

Source§

fn into_val(&self, _e: &Env) -> BytesN<192>

Source§

impl IntoVal<Env, BytesN<48>> for Fp

Source§

fn into_val(&self, _e: &Env) -> BytesN<48>

Source§

impl IntoVal<Env, BytesN<96>> for Fp2

Source§

fn into_val(&self, _e: &Env) -> BytesN<96>

Source§

impl IntoVal<Env, BytesN<96>> for G1Affine

Source§

fn into_val(&self, _e: &Env) -> BytesN<96>

Source§

impl<const N: usize> IntoVal<Env, BytesN<N>> for Hash<N>

Source§

fn into_val(&self, _e: &Env) -> BytesN<N>

Source§

impl<const N: usize> Ord for BytesN<N>

Source§

fn cmp(&self, other: &Self) -> 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 N: usize> PartialEq<[u8; N]> for BytesN<N>

Source§

fn eq(&self, other: &[u8; N]) -> 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 N: usize> PartialEq<BytesN<N>> for [u8; N]

Source§

fn eq(&self, other: &BytesN<N>) -> 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 N: usize> PartialEq for BytesN<N>

Source§

fn eq(&self, other: &Self) -> 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 N: usize> PartialOrd<[u8; N]> for BytesN<N>

Source§

fn partial_cmp(&self, other: &[u8; N]) -> 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<const N: usize> PartialOrd<BytesN<N>> for [u8; N]

Source§

fn partial_cmp(&self, other: &BytesN<N>) -> 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<const N: usize> PartialOrd for BytesN<N>

Source§

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 · 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<const N: usize> SorobanArbitrary for BytesN<N>

Available on crate feature testutils only.
Source§

type Prototype = ArbitraryBytesN<N>

A type that implements Arbitrary and can be converted to this SorobanArbitrary type.
Source§

impl<const N: usize> TryFrom<&Bytes> for BytesN<N>

Source§

type Error = ConversionError

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

fn try_from(bin: &Bytes) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<const N: usize> TryFrom<&BytesN<N>> for ScVal

Source§

type Error = ConversionError

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

fn try_from(v: &BytesN<N>) -> Result<Self, ConversionError>

Performs the conversion.
Source§

impl<const N: usize> TryFrom<Bytes> for BytesN<N>

Source§

type Error = ConversionError

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

fn try_from(bin: Bytes) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<const N: usize> TryFrom<BytesN<N>> for ScVal

Source§

type Error = ConversionError

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

fn try_from(v: BytesN<N>) -> Result<Self, ConversionError>

Performs the conversion.
Source§

impl<const N: usize> TryFromVal<Env, &BytesN<N>> for Val

Source§

type Error = ConversionError

Source§

fn try_from_val(_env: &Env, v: &&BytesN<N>) -> Result<Self, Self::Error>

Source§

impl<const N: usize> TryFromVal<Env, [u8; N]> for BytesN<N>

Source§

type Error = ConversionError

Source§

fn try_from_val(env: &Env, v: &[u8; N]) -> Result<Self, Self::Error>

Source§

impl<const N: usize> TryFromVal<Env, BytesN<N>> for [u8; N]

Source§

type Error = ConversionError

Source§

fn try_from_val(_env: &Env, v: &BytesN<N>) -> Result<Self, Self::Error>

Source§

impl<const N: usize> TryFromVal<Env, BytesN<N>> for Bytes

Source§

type Error = ConversionError

Source§

fn try_from_val(_env: &Env, v: &BytesN<N>) -> Result<Self, Self::Error>

Source§

impl<const N: usize> TryFromVal<Env, BytesN<N>> for BytesN<N>

Source§

type Error = ConversionError

Source§

fn try_from_val(_env: &Env, v: &BytesN<N>) -> Result<Self, Self::Error>

Source§

impl<const N: usize> TryFromVal<Env, BytesN<N>> for Val

Source§

type Error = ConversionError

Source§

fn try_from_val(_env: &Env, v: &BytesN<N>) -> Result<Self, Self::Error>

Source§

impl<const N: usize> TryFromVal<Env, BytesObject> for BytesN<N>

Source§

impl<const N: usize> TryFromVal<Env, ScVal> for BytesN<N>

Source§

type Error = ConversionError

Source§

fn try_from_val(env: &Env, val: &ScVal) -> Result<Self, Self::Error>

Source§

impl<const N: usize> TryFromVal<Env, Val> for BytesN<N>

Source§

type Error = ConversionError

Source§

fn try_from_val(env: &Env, val: &Val) -> Result<Self, Self::Error>

Source§

impl<const N: usize> Eq for BytesN<N>

Auto Trait Implementations§

§

impl<const N: usize> Freeze for BytesN<N>

§

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§

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<T, C> Compare<&T> for C
where C: Compare<T>,

Source§

type Error = <C as Compare<T>>::Error

Source§

fn compare(&self, a: &&T, b: &&T) -> Result<Ordering, <C as Compare<&T>>::Error>

Source§

impl<T, U, E, C> Compare<(T, U)> for C
where C: Compare<T, Error = E, Error = E> + Compare<U>,

Source§

type Error = E

Source§

fn compare( &self, a: &(T, U), b: &(T, U), ) -> Result<Ordering, <C as Compare<(T, U)>>::Error>

Source§

impl<T, U, V, E, C> Compare<(T, U, V)> for C
where C: Compare<T, Error = E, Error = E, Error = E> + Compare<U> + Compare<V>,

Source§

impl<T, U, V, W, E, C> Compare<(T, U, V, W)> for C
where C: Compare<T, Error = E, Error = E, Error = E, Error = E> + Compare<U> + Compare<V> + Compare<W>,

Source§

impl<T, U, V, W, X, E, C> Compare<(T, U, V, W, X)> for C
where C: Compare<T, Error = E, Error = E, Error = E, Error = E, Error = E> + Compare<U> + Compare<V> + Compare<W> + Compare<X>,

Source§

impl<T, C> Compare<Box<T>> for C
where C: Compare<T>,

Source§

type Error = <C as Compare<T>>::Error

Source§

fn compare( &self, a: &Box<T>, b: &Box<T>, ) -> Result<Ordering, <C as Compare<Box<T>>>::Error>

Source§

impl<T, C> Compare<Option<T>> for C
where C: Compare<T>,

Source§

type Error = <C as Compare<T>>::Error

Source§

fn compare( &self, a: &Option<T>, b: &Option<T>, ) -> Result<Ordering, <C as Compare<Option<T>>>::Error>

Source§

impl<T, C> Compare<Rc<T>> for C
where C: Compare<T>,

Source§

type Error = <C as Compare<T>>::Error

Source§

fn compare( &self, a: &Rc<T>, b: &Rc<T>, ) -> Result<Ordering, <C as Compare<Rc<T>>>::Error>

Source§

impl<T, C> Compare<Vec<T>> for C
where C: Compare<T>,

Source§

type Error = <C as Compare<T>>::Error

Source§

fn compare( &self, a: &Vec<T>, b: &Vec<T>, ) -> Result<Ordering, <C as Compare<Vec<T>>>::Error>

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

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

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

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

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

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<E, T, U> FromVal<E, T> for U
where E: Env, U: TryFromVal<E, T>,

Source§

fn from_val(e: &E, v: &T) -> U

Source§

impl<T> FromXdr for T
where T: TryFromVal<Env, Val>,

Source§

type Error = <T as TryFromVal<Env, Val>>::Error

Source§

fn from_xdr(env: &Env, b: &Bytes) -> Result<T, <T as FromXdr>::Error>

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<E, T, U> IntoVal<E, T> for U
where E: Env, T: FromVal<E, U>,

Source§

fn into_val(&self, e: &E) -> T

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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> ToXdr for T
where T: IntoVal<Env, Val>,

Source§

fn to_xdr(self, env: &Env) -> Bytes

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

impl<E, T, U> TryIntoVal<E, T> for U
where E: Env, T: TryFromVal<E, U>,

Source§

type Error = <T as TryFromVal<E, U>>::Error

Source§

fn try_into_val(&self, env: &E) -> Result<T, <U as TryIntoVal<E, T>>::Error>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V