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§

Create an empty Bytes.

Create a Bytes from the given [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.

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.

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.

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.

Copy the bytes from slice into Bytes.

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

Copy the bytes in Bytes into the given slice.

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

Trait Implementations§

Converts this type into a shared reference of the (usually inferred) input type.
Immutably borrows from an owned value. Read more
Immutably borrows from an owned value. Read more
Immutably borrows from an owned value. Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
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.
Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.