Struct soroban_sdk::Bytes
source · [−]#[repr(transparent)]pub struct Bytes(_);
Expand description
Bytes is a contiguous growable 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
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
sourceimpl Bytes
impl Bytes
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
sourcepub fn from_array<const N: usize>(env: &Env, items: &[u8; N]) -> Bytes
pub fn from_array<const N: usize>(env: &Env, items: &[u8; N]) -> Bytes
Create a Bytes from the given [u8]
.
pub fn from_slice(env: &Env, items: &[u8]) -> Bytes
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
pub fn remove(&mut self, i: u32) -> Option<()>
pub fn remove_unchecked(&mut self, i: u32)
pub fn push(&mut self, x: u8)
pub fn pop(&mut self) -> Option<u8>
pub fn pop_unchecked(&mut self) -> u8
sourcepub fn insert_from_bytes(&mut self, i: u32, bytes: Bytes)
pub fn insert_from_bytes(&mut self, i: u32, bytes: Bytes)
sourcepub fn insert_from_slice(&mut self, i: u32, slice: &[u8])
pub fn insert_from_slice(&mut self, i: u32, slice: &[u8])
pub fn append(&mut self, other: &Bytes)
pub fn extend_from_array<const N: usize>(&mut self, array: &[u8; N])
pub fn extend_from_slice(&mut self, slice: &[u8])
sourcepub fn copy_from_slice(&mut self, i: u32, slice: &[u8])
pub fn copy_from_slice(&mut self, i: u32, slice: &[u8])
sourcepub fn copy_into_slice(&self, slice: &mut [u8])
pub fn copy_into_slice(&self, slice: &mut [u8])
pub fn slice(&self, r: impl RangeBounds<u32>) -> Self
pub fn iter(&self) -> BinIter
Trait Implementations
sourceimpl IntoIterator for Bytes
impl IntoIterator for Bytes
sourceimpl Ord for Bytes
impl Ord for Bytes
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 PartialEq<Bytes> for Bytes
impl PartialEq<Bytes> for Bytes
sourceimpl PartialOrd<Bytes> for Bytes
impl PartialOrd<Bytes> for Bytes
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 TryFromVal<Env, Object> for Bytes
impl TryFromVal<Env, Object> for Bytes
type Error = ConversionError
fn try_from_val(env: &Env, val: Object) -> Result<Self, Self::Error>
sourceimpl TryFromVal<Env, RawVal> for Bytes
impl TryFromVal<Env, RawVal> for Bytes
sourceimpl TryFromVal<Env, ScVal> for Bytes
impl TryFromVal<Env, ScVal> for Bytes
type Error = ConversionError
fn try_from_val(env: &Env, val: ScVal) -> Result<Self, Self::Error>
sourceimpl TryIntoVal<Env, Bytes> for Object
impl TryIntoVal<Env, Bytes> for Object
type Error = ConversionError
fn try_into_val(self, env: &Env) -> Result<Bytes, Self::Error>
fn try_into_env_val(self, env: &E) -> Result<EnvVal<E, V>, Self::Error>
sourceimpl TryIntoVal<Env, Bytes> for RawVal
impl TryIntoVal<Env, Bytes> for RawVal
type Error = ConversionError
fn try_into_val(self, env: &Env) -> Result<Bytes, Self::Error>
fn try_into_env_val(self, env: &E) -> Result<EnvVal<E, V>, Self::Error>
sourceimpl TryIntoVal<Env, Bytes> for ScVal
impl TryIntoVal<Env, Bytes> for ScVal
type Error = ConversionError
fn try_into_val(self, env: &Env) -> Result<Bytes, Self::Error>
fn try_into_env_val(self, env: &E) -> Result<EnvVal<E, V>, Self::Error>
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
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