pub struct Piece(/* private fields */);Expand description
A piece of archival history.
This version is allocated on the heap, for stack-allocated piece see InnerPiece.
Internally piece contains a record and corresponding proof that together with segment root of the segment this piece belongs to can be used to verify that a piece belongs to the actual archival history of the blockchain.
Piece is a shared buffer, which is cheap to clone. Mutable access to a piece whose allocation is
still shared (with other pieces or with FlatPieces it was created from, for example) copies
it into a new allocation first.
Implementations§
Source§impl Piece
impl Piece
Sourcepub fn from_parts(header: &PieceHeader, record: &Record) -> Self
pub fn from_parts(header: &PieceHeader, record: &Record) -> Self
Create a piece from its header and record.
Contents are written into a new allocation directly, without zeroing it first or going through the stack.
Sourcepub fn buffer(&self) -> &SharedAlignedBuffer<Align1>
pub fn buffer(&self) -> &SharedAlignedBuffer<Align1>
Shared buffer with the contents of the piece
Methods from Deref<Target = InnerPiece>§
Sourcepub fn is_valid(
&self,
super_segment_root: &SuperSegmentRoot,
num_segments: u32,
max_segment_index: SegmentIndex,
piece_index: PieceIndex,
) -> bool
pub fn is_valid( &self, super_segment_root: &SuperSegmentRoot, num_segments: u32, max_segment_index: SegmentIndex, piece_index: PieceIndex, ) -> bool
Check whether the piece is the piece at piece_index of the global history.
super_segment_root, num_segments and max_segment_index are those of the super segment
that contains the segment of piece_index, which determines the position of the segment in
the super segment. Returns false if the super segment doesn’t contain it.
Sourcepub fn record_root(&self) -> RecordRoot
pub fn record_root(&self) -> RecordRoot
Root of the record contained within a piece.
It is re-derived on every call of this function.
Trait Implementations§
Source§impl Decode for Piece
Available on crate feature scale-codec only.
impl Decode for Piece
scale-codec only.Source§fn decode<I>(input: &mut I) -> Result<Self, Error>where
I: Input,
fn decode<I>(input: &mut I) -> Result<Self, Error>where
I: Input,
Source§fn encoded_fixed_size() -> Option<usize>
fn encoded_fixed_size() -> Option<usize>
§fn decode_into<I>(
input: &mut I,
dst: &mut MaybeUninit<Self>,
) -> Result<DecodeFinished, Error>where
I: Input,
fn decode_into<I>(
input: &mut I,
dst: &mut MaybeUninit<Self>,
) -> Result<DecodeFinished, Error>where
I: Input,
Source§impl<'de> Deserialize<'de> for Piece
Available on crate feature serde only.
impl<'de> Deserialize<'de> for Piece
serde only.Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl Encode for Piece
Available on crate feature scale-codec only.Encoded as bytes of the piece without length, since the size of a piece is fixed
impl Encode for Piece
scale-codec only.Encoded as bytes of the piece without length, since the size of a piece is fixed
Source§fn size_hint(&self) -> usize
fn size_hint(&self) -> usize
Source§fn encode_to<O>(&self, dest: &mut O)where
O: Output + ?Sized,
fn encode_to<O>(&self, dest: &mut O)where
O: Output + ?Sized,
Source§fn using_encoded<R, F>(&self, f: F) -> R
fn using_encoded<R, F>(&self, f: F) -> R
Source§fn encoded_size(&self) -> usize
fn encoded_size(&self) -> usize
impl EncodeLike for Piece
scale-codec only.impl Eq for Piece
Source§impl From<&InnerPiece> for Piece
impl From<&InnerPiece> for Piece
Source§fn from(value: &InnerPiece) -> Self
fn from(value: &InnerPiece) -> Self
Source§impl Serialize for Piece
Available on crate feature serde only.Serialized as a hex string in human-readable formats and as bytes otherwise
impl Serialize for Piece
serde only.Serialized as a hex string in human-readable formats and as bytes otherwise
Auto Trait Implementations§
impl Forget for Piece
impl Freeze for Piece
impl Move for Piece
impl RefUnwindSafe for Piece
impl Send for Piecewhere
InnerBuffer: Send,
impl Sync for Piecewhere
InnerBuffer: Sync,
impl Unpin for Piece
impl UnsafeUnpin for Piece
impl UnwindSafe for Piece
Blanket Implementations§
§impl<T, U> AsByteSlice<T> for U
impl<T, U> AsByteSlice<T> for U
fn as_byte_slice(&self) -> &[u8] ⓘ
§impl<T, U> AsMutByteSlice<T> for U
impl<T, U> AsMutByteSlice<T> for U
fn as_mut_byte_slice(&mut self) -> &mut [u8] ⓘ
§impl<U> AsMutSliceOf for U
impl<U> AsMutSliceOf for U
fn as_mut_slice_of<T>(&mut self) -> Result<&mut [T], Error>where
T: FromByteSlice,
§impl<U> AsSliceOf for U
impl<U> AsSliceOf for U
fn as_slice_of<T>(&self) -> Result<&[T], Error>where
T: FromByteSlice,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<S> Codec for Swhere
S: Decode + Encode,
§impl<T> DecodeAll for Twhere
T: Decode,
impl<T> DecodeAll for Twhere
T: Decode,
§fn decode_all(input: &mut &[u8]) -> Result<T, Error>
fn decode_all(input: &mut &[u8]) -> Result<T, Error>
Self and consume all of the given input data. Read more§impl<T> DecodeLimit for Twhere
T: Decode,
impl<T> DecodeLimit for Twhere
T: Decode,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
impl<T> EncodeLike<&&T> for Twhere
T: Encode,
impl<T> EncodeLike<&T> for Twhere
T: Encode,
impl<T> EncodeLike<&mut T> for Twhere
T: Encode,
impl<T> EncodeLike<Arc<T>> for Twhere
T: Encode,
impl<T> EncodeLike<Box<T>> for Twhere
T: Encode,
impl<T> EncodeLike<Cow<'_, T>> for Twhere
T: ToOwned + Encode,
impl<T> EncodeLike<Rc<T>> for Twhere
T: Encode,
impl<S> FullCodec for Swhere
S: Decode + FullEncode,
impl<S> FullEncode for Swhere
S: Encode + EncodeLike,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> KeyedVec for Twhere
T: Codec,
impl<T> KeyedVec for Twhere
T: Codec,
§fn to_keyed_vec(&self, prepend_key: &[u8]) -> Vec<u8> ⓘ
fn to_keyed_vec(&self, prepend_key: &[u8]) -> Vec<u8> ⓘ
Self prepended by given slice.§impl<H> NewMerkleHasherForTreeSize for Hwhere
H: Default,
impl<H> NewMerkleHasherForTreeSize for Hwhere
H: Default,
§fn new_for_tree_size(_num_leaves: u64) -> H
fn new_for_tree_size(_num_leaves: u64) -> H
num_leaves leaves§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> ToHex for T
impl<T> ToHex for T
Source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
self into the result. Lower case
letters are used (e.g. f9b4ca)Source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
self into the result. Upper case
letters are used (e.g. F9B4CA)