Struct celestia_types::Share

source ·
pub struct Share {
    pub data: [u8; 512],
}
Expand description

A single fixed-size chunk of data which is used to form an ExtendedDataSquare.

All data in Celestia is split into Shares before being put into a block’s data square. See Blob::to_shares.

All shares have the fixed size of 512 bytes and the following structure:

| Namespace | InfoByte | (optional) sequence length | data |

sequence length is the length of the original data in bytes and is present only in the first of the shares the data was split into.

Fields§

§data: [u8; 512]

A raw data of the share.

Implementations§

source§

impl Share

source

pub fn from_raw(data: &[u8]) -> Result<Self>

Create a new Share from raw bytes.

§Errors

This function will return an error if the slice length isn’t SHARE_SIZE or if a namespace encoded in the share is invalid.

§Example
use celestia_types::Share;

let raw = [0; 512];
let share = Share::from_raw(&raw).unwrap();
source

pub fn namespace(&self) -> Namespace

Get the Namespace the Share belongs to.

source

pub fn data(&self) -> &[u8]

Get all the data that follows the Namespace of the Share.

This will include also the InfoByte and the sequence length.

source

pub fn to_vec(&self) -> Vec<u8>

Converts this Share into the raw bytes vector.

This will include also the InfoByte and the sequence length.

source

pub fn info_byte(&self) -> InfoByte

Return Share’s InfoByte

source

pub fn sequence_length(&self) -> Option<u32>

For first share in a sequence, return sequence length, None for continuation shares

Trait Implementations§

source§

impl AsMut<[u8]> for Share

source§

fn as_mut(&mut self) -> &mut [u8]

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl AsRef<[u8]> for Share

source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Block<NMT_ID_SIZE> for Share

source§

fn cid(&self) -> Result<CidGeneric<NMT_ID_SIZE>, CidError>

Get the CID of the block.
source§

fn data(&self) -> &[u8]

Get the data of the block.
source§

impl Clone for Share

source§

fn clone(&self) -> Share

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 Share

source§

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

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

impl<'de> Deserialize<'de> for Share

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl PartialEq for Share

source§

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

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

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

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

impl Serialize for Share

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for Share

source§

impl StructuralPartialEq for Share

Auto Trait Implementations§

§

impl Freeze for Share

§

impl RefUnwindSafe for Share

§

impl Send for Share

§

impl Sync for Share

§

impl Unpin for Share

§

impl UnwindSafe for Share

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where 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<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToHex for T
where T: AsRef<[u8]>,

source§

fn encode_hex<U>(&self) -> U
where U: FromIterator<char>,

Encode the hex strict representing self into the result. Lower case letters are used (e.g. f9b4ca)
source§

fn encode_hex_upper<U>(&self) -> U
where U: FromIterator<char>,

Encode the hex strict representing self into the result. Upper case letters are used (e.g. F9B4CA)
source§

impl<T> ToOwned for T
where 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, U> TryFrom<U> for T
where 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 T
where 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.
source§

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

source§

fn vzip(self) -> V

source§

impl<S> CondSend for S
where S: Send,

source§

impl<S> CondSync for S
where S: Send + Sync,

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,