Struct soroban_sdk::Binary
source · [−]#[repr(transparent)]pub struct Binary(_);
Expand description
Binary 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 Binary.
Binary values can be stored as ContractData, or in other types like Vec, Map, etc.
Examples
Binary values can be created from slices:
use soroban_sdk::{Binary, Env};
let env = Env::default();
let bin = Binary::from_slice(&env, &[0; 32]);
assert_eq!(bin.len(), 32);
Implementations
sourceimpl Binary
impl Binary
sourcepub fn from_array<const N: usize>(env: &Env, items: [u8; N]) -> Binary
pub fn from_array<const N: usize>(env: &Env, items: [u8; N]) -> Binary
Create a binary from the given [u8]
.
pub fn from_slice(env: &Env, items: &[u8]) -> Binary
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
pub fn insert(&mut self, i: u32, x: u8)
pub fn append(&mut self, other: &Binary)
pub fn extend_from_array<const N: usize>(&mut self, items: [u8; N])
pub fn extend_from_slice(&mut self, items: &[u8])
pub fn slice(&self, r: impl RangeBounds<u32>) -> Self
pub fn iter(&self) -> BinIter
Trait Implementations
sourceimpl<const N: usize> AsRef<Binary> for FixedBinary<N>
impl<const N: usize> AsRef<Binary> for FixedBinary<N>
sourceimpl<const N: usize> Borrow<Binary> for &FixedBinary<N>
impl<const N: usize> Borrow<Binary> for &FixedBinary<N>
sourceimpl<const N: usize> Borrow<Binary> for &mut FixedBinary<N>
impl<const N: usize> Borrow<Binary> for &mut FixedBinary<N>
sourceimpl<const N: usize> Borrow<Binary> for FixedBinary<N>
impl<const N: usize> Borrow<Binary> for FixedBinary<N>
sourceimpl<const N: usize> From<FixedBinary<N>> for Binary
impl<const N: usize> From<FixedBinary<N>> for Binary
sourcefn from(v: FixedBinary<N>) -> Self
fn from(v: FixedBinary<N>) -> Self
Converts to this type from the input type.
sourceimpl IntoIterator for Binary
impl IntoIterator for Binary
sourceimpl Ord for Binary
impl Ord for Binary
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 PartialOrd<Binary> for Binary
impl PartialOrd<Binary> for Binary
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> TryFrom<Binary> for FixedBinary<N>
impl<const N: usize> TryFrom<Binary> for FixedBinary<N>
sourceimpl TryIntoVal<Env, Binary> for RawVal
impl TryIntoVal<Env, Binary> for RawVal
type Error = ConversionError
fn try_into_val(self, env: &Env) -> Result<Binary, Self::Error>
fn try_into_env_val(self, env: &E) -> Result<EnvVal<E, V>, Self::Error>
sourceimpl TryIntoVal<Env, Binary> for ScVal
impl TryIntoVal<Env, Binary> for ScVal
type Error = ConversionError
fn try_into_val(self, env: &Env) -> Result<Binary, Self::Error>
fn try_into_env_val(self, env: &E) -> Result<EnvVal<E, V>, Self::Error>
impl Eq for Binary
Auto Trait Implementations
impl !RefUnwindSafe for Binary
impl !Send for Binary
impl !Sync for Binary
impl Unpin for Binary
impl !UnwindSafe for Binary
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