Struct soroban_sdk::Bytes

source ·
pub struct Bytes { /* private fields */ }
Expand description

Bytes is a contiguous growable 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

Bytes values can be created from slices:

use soroban_sdk::{Bytes, Env};

let env = Env::default();
let bytes = Bytes::from_slice(&env, &[1; 32]);
assert_eq!(bytes.len(), 32);
let mut slice = [0u8; 32];
bytes.copy_into_slice(&mut slice);
assert_eq!(slice, [1u8; 32]);

Implementations§

source§

impl Bytes

source

pub fn env(&self) -> &Env

source

pub fn as_raw(&self) -> &RawVal

source

pub fn to_raw(&self) -> RawVal

source

pub fn as_object(&self) -> &BytesObject

source

pub fn to_object(&self) -> BytesObject

source

pub fn new(env: &Env) -> Bytes

Create an empty Bytes.

source

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

Create a Bytes from the given [u8].

source

pub fn from_slice(env: &Env, items: &[u8]) -> Bytes

source

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

source

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

source

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

source

pub fn is_empty(&self) -> bool

source

pub fn len(&self) -> u32

source

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

source

pub fn first_unchecked(&self) -> u8

source

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

source

pub fn last_unchecked(&self) -> u8

source

pub fn remove(&mut self, i: u32) -> Option<()>

source

pub fn remove_unchecked(&mut self, i: u32)

source

pub fn push(&mut self, x: u8)

source

pub fn pop(&mut self) -> Option<u8>

source

pub fn pop_unchecked(&mut self) -> u8

source

pub fn insert(&mut self, i: u32, b: u8)

Insert the byte into this Bytes at position indicated by i, and growing the size of Bytes by 1.

Panics

When i is greater than the length of Bytes.

source

pub fn insert_from_bytes(&mut self, i: u32, bytes: Bytes)

Insert the bytes in bytes into this Bytes starting at position indicated by i, and growing the size of Bytes by the length of `bytes.

Panics

When i is greater than the length of Bytes.

source

pub fn insert_from_array<const N: usize>(&mut self, i: u32, array: &[u8; N])

Insert the bytes in array into this Bytes starting at position indicated by i, and growing the size of Bytes by the length of `bytes.

Panics

When i is greater than the length of Bytes.

source

pub fn insert_from_slice(&mut self, i: u32, slice: &[u8])

Insert the bytes in slice into this Bytes starting at position indicated by i, and growing the size of Bytes by the length of `bytes.

Panics

When i is greater than the length of Bytes.

source

pub fn append(&mut self, other: &Bytes)

source

pub fn extend_from_array<const N: usize>(&mut self, array: &[u8; N])

source

pub fn extend_from_slice(&mut self, slice: &[u8])

source

pub fn copy_from_slice(&mut self, i: u32, slice: &[u8])

Copy the bytes from slice into Bytes.

The full number of bytes in slice are always copied and Bytes is grown if necessary.

source

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

Copy the bytes in Bytes into the given slice.

The minimum number of bytes are copied to either exhaust Bytes or fill slice.

source

pub fn slice(&self, r: impl RangeBounds<u32>) -> Self

source

pub fn iter(&self) -> BinIter

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 Clone for Bytes

source§

fn clone(&self) -> Bytes

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 Debug for Bytes

source§

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

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

impl From<&Bytes> for Bytes

source§

fn from(v: &Bytes) -> Self

Converts to this type from the input type.
source§

impl From<&Bytes> for BytesObject

source§

fn from(v: &Bytes) -> 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 From<Bytes> for BytesObject

source§

fn from(v: Bytes) -> Self

Converts to this type from the input type.
source§

impl From<Bytes> for RawVal

source§

fn from(v: Bytes) -> 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 IntoIterator for Bytes

§

type Item = u8

The type of the elements being iterated over.
§

type IntoIter = BinIter

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 Ord for Bytes

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) -> Selfwhere Self: Sized,

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

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

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

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

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

impl PartialEq<Bytes> for Bytes

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<Bytes> for Bytes

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

This method 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

This method 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

This method 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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<const N: usize> TryFrom<&Bytes> for [u8; N]

§

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<&Bytes> for BytesN<N>

§

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 TryFrom<&Bytes> for ScVal

§

type Error = ConversionError

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

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

Performs the conversion.
source§

impl<const N: usize> TryFrom<Bytes> for [u8; N]

§

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<Bytes> for BytesN<N>

§

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 TryFrom<Bytes> for ScVal

§

type Error = ConversionError

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

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

Performs the conversion.
source§

impl TryFromVal<Env, &[u8]> for Bytes

§

type Error = ConversionError

source§

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

source§

impl TryFromVal<Env, &str> for Bytes

§

type Error = ConversionError

source§

fn try_from_val(env: &Env, v: &&str) -> Result<Self, Self::Error>

source§

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

§

type Error = ConversionError

source§

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

source§

impl TryFromVal<Env, Bytes> for Bytes

§

type Error = ConversionError

source§

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

source§

impl TryFromVal<Env, Bytes> for RawVal

§

type Error = ConversionError

source§

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

source§

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

§

type Error = ConversionError

source§

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

source§

impl TryFromVal<Env, BytesObject> for Bytes

§

type Error = Infallible

source§

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

source§

impl TryFromVal<Env, RawVal> for Bytes

§

type Error = ConversionError

source§

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

source§

impl TryFromVal<Env, ScVal> for Bytes

§

type Error = ConversionError

source§

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

source§

impl Eq for Bytes

Auto Trait Implementations§

§

impl !RefUnwindSafe for Bytes

§

impl !Send for Bytes

§

impl !Sync for Bytes

§

impl Unpin for Bytes

§

impl !UnwindSafe for Bytes

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

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

§

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

§

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

§

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

§

type Error = E

§

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

§

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

§

type Error = E

§

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

§

impl<T, C> Compare<Box<T, Global>> for Cwhere C: Compare<T>,

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

impl<T, C> Compare<Vec<T, Global>> for Cwhere C: Compare<T>,

§

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

§

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

§

impl<T> Downcast for Twhere T: Any,

§

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

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

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

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

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

source§

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

source§

impl<T> FromXdr for Twhere T: TryFromVal<Env, RawVal>,

§

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

source§

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

source§

impl<T, U> Into<U> for Twhere 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<E, T, U> IntoVal<E, T> for Uwhere E: Env, T: FromVal<E, U>,

source§

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

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere T: IntoVal<Env, RawVal>,

source§

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

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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

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

§

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

§

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

§

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

§

fn vzip(self) -> V