FromBytes

Trait FromBytes 

Source
pub trait FromBytes
where Self: Sized,
{ // Required methods fn from_bytes(bytes: &[u8]) -> Result<Self>; fn from_bytes_vec(bytes: Vec<u8>) -> Result<Self>; }
Expand description

A trait to convert Bytes into a specific type.

This trait is implemented for various types such as Vec<u8>, String, &str, and primitive types like u8, i32, etc.

Additionally it supports an JSON deserializable type via the serde and serde_json crates.

Required Methods§

Source

fn from_bytes(bytes: &[u8]) -> Result<Self>

A way to convert the Bytes into the implementing type without consuming the original bytes.

§Errors

There are several reasons why this conversion might fail returning an errors::SDKError:

§Examples
use seda_sdk_rs::bytes::{FromBytes, ToBytes};
let bytes = "Hello, world!".to_bytes();
let string: String = String::from_bytes(&bytes).expect("Should be valid UTF-8");
assert_eq!(string, "Hello, world!");
Source

fn from_bytes_vec(bytes: Vec<u8>) -> Result<Self>

A way to convert the Bytes into the implementing type and consume the original bytes.

§Errors

There are several reasons why this conversion might fail returning an errors::SDKError:

§Examples
use seda_sdk_rs::bytes::{FromBytes, ToBytes};
let bytes = "Hello, world!".to_bytes();
let string: String = String::from_bytes_vec(bytes.eject()).expect("Should be valid UTF-8");
assert_eq!(string, "Hello, world!");

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl FromBytes for bool

Source§

fn from_bytes(bytes: &[u8]) -> Result<Self>

Source§

fn from_bytes_vec(bytes: Vec<u8>) -> Result<Self>

Source§

impl FromBytes for f32

Source§

fn from_bytes(bytes: &[u8]) -> Result<Self>

Source§

fn from_bytes_vec(bytes: Vec<u8>) -> Result<Self>

Source§

impl FromBytes for f64

Source§

fn from_bytes(bytes: &[u8]) -> Result<Self>

Source§

fn from_bytes_vec(bytes: Vec<u8>) -> Result<Self>

Source§

impl FromBytes for i8

Source§

fn from_bytes(bytes: &[u8]) -> Result<Self>

Source§

fn from_bytes_vec(bytes: Vec<u8>) -> Result<Self>

Source§

impl FromBytes for i32

Source§

fn from_bytes(bytes: &[u8]) -> Result<Self>

Source§

fn from_bytes_vec(bytes: Vec<u8>) -> Result<Self>

Source§

impl FromBytes for i64

Source§

fn from_bytes(bytes: &[u8]) -> Result<Self>

Source§

fn from_bytes_vec(bytes: Vec<u8>) -> Result<Self>

Source§

impl FromBytes for i128

Source§

fn from_bytes(bytes: &[u8]) -> Result<Self>

Source§

fn from_bytes_vec(bytes: Vec<u8>) -> Result<Self>

Source§

impl FromBytes for u8

Source§

fn from_bytes(bytes: &[u8]) -> Result<Self>

Source§

fn from_bytes_vec(bytes: Vec<u8>) -> Result<Self>

Source§

impl FromBytes for u32

Source§

fn from_bytes(bytes: &[u8]) -> Result<Self>

Source§

fn from_bytes_vec(bytes: Vec<u8>) -> Result<Self>

Source§

impl FromBytes for u64

Source§

fn from_bytes(bytes: &[u8]) -> Result<Self>

Source§

fn from_bytes_vec(bytes: Vec<u8>) -> Result<Self>

Source§

impl FromBytes for u128

Source§

fn from_bytes(bytes: &[u8]) -> Result<Self>

Source§

fn from_bytes_vec(bytes: Vec<u8>) -> Result<Self>

Source§

impl FromBytes for String

Source§

fn from_bytes(bytes: &[u8]) -> Result<Self>

Source§

fn from_bytes_vec(bytes: Vec<u8>) -> Result<Self>

Source§

impl FromBytes for Vec<u8>

Source§

fn from_bytes(bytes: &[u8]) -> Result<Self>

Source§

fn from_bytes_vec(bytes: Vec<u8>) -> Result<Self>

Implementors§