pub struct PieceArray(/* private fields */);
Expand description
A piece of archival history in Subspace Network.
This version is allocated on the stack, for heap-allocated piece see Piece
.
Internally piece contains a record and corresponding witness that together with segment commitment of the segment this piece belongs to can be used to verify that a piece belongs to the actual archival history of the blockchain.
Implementations§
source§impl PieceArray
impl PieceArray
sourcepub fn split(&self) -> (&Record, &RecordCommitment, &RecordWitness)
pub fn split(&self) -> (&Record, &RecordCommitment, &RecordWitness)
Split piece into underlying components.
sourcepub fn split_mut(
&mut self,
) -> (&mut Record, &mut RecordCommitment, &mut RecordWitness)
pub fn split_mut( &mut self, ) -> (&mut Record, &mut RecordCommitment, &mut RecordWitness)
Split piece into underlying mutable components.
sourcepub fn record_mut(&mut self) -> &mut Record
pub fn record_mut(&mut self) -> &mut Record
Mutable record contained within a piece.
sourcepub fn commitment(&self) -> &RecordCommitment
pub fn commitment(&self) -> &RecordCommitment
Commitment contained within a piece.
sourcepub fn commitment_mut(&mut self) -> &mut RecordCommitment
pub fn commitment_mut(&mut self) -> &mut RecordCommitment
Mutable commitment contained within a piece.
sourcepub fn witness(&self) -> &RecordWitness
pub fn witness(&self) -> &RecordWitness
Witness contained within a piece.
sourcepub fn witness_mut(&mut self) -> &mut RecordWitness
pub fn witness_mut(&mut self) -> &mut RecordWitness
Mutable witness contained within a piece.
sourcepub fn slice_to_repr(value: &[Self]) -> &[[u8; 1048672]]
pub fn slice_to_repr(value: &[Self]) -> &[[u8; 1048672]]
Convenient conversion from slice of piece array to underlying representation for efficiency purposes.
sourcepub fn slice_from_repr(value: &[[u8; 1048672]]) -> &[Self]
pub fn slice_from_repr(value: &[[u8; 1048672]]) -> &[Self]
Convenient conversion from slice of underlying representation to piece array for efficiency purposes.
sourcepub fn slice_mut_to_repr(value: &mut [Self]) -> &mut [[u8; 1048672]]
pub fn slice_mut_to_repr(value: &mut [Self]) -> &mut [[u8; 1048672]]
Convenient conversion from mutable slice of piece array to underlying representation for efficiency purposes.
sourcepub fn slice_mut_from_repr(value: &mut [[u8; 1048672]]) -> &mut [Self]
pub fn slice_mut_from_repr(value: &mut [[u8; 1048672]]) -> &mut [Self]
Convenient conversion from mutable slice of underlying representation to piece array for efficiency purposes.
Methods from Deref<Target = [u8; 1048672]>§
sourcepub fn as_ascii(&self) -> Option<&[AsciiChar; N]>
🔬This is a nightly-only experimental API. (ascii_char
)
pub fn as_ascii(&self) -> Option<&[AsciiChar; N]>
ascii_char
)Converts this array of bytes into an array of ASCII characters,
or returns None
if any of the characters is non-ASCII.
§Examples
#![feature(ascii_char)]
const HEX_DIGITS: [std::ascii::Char; 16] =
*b"0123456789abcdef".as_ascii().unwrap();
assert_eq!(HEX_DIGITS[1].as_str(), "1");
assert_eq!(HEX_DIGITS[10].as_str(), "a");
sourcepub unsafe fn as_ascii_unchecked(&self) -> &[AsciiChar; N]
🔬This is a nightly-only experimental API. (ascii_char
)
pub unsafe fn as_ascii_unchecked(&self) -> &[AsciiChar; N]
ascii_char
)Converts this array of bytes into an array of ASCII characters, without checking whether they’re valid.
§Safety
Every byte in the array must be in 0..=127
, or else this is UB.
1.57.0 · sourcepub fn as_slice(&self) -> &[T]
pub fn as_slice(&self) -> &[T]
Returns a slice containing the entire array. Equivalent to &s[..]
.
1.57.0 · sourcepub fn as_mut_slice(&mut self) -> &mut [T]
pub fn as_mut_slice(&mut self) -> &mut [T]
Returns a mutable slice containing the entire array. Equivalent to
&mut s[..]
.
1.77.0 · sourcepub fn each_ref(&self) -> [&T; N]
pub fn each_ref(&self) -> [&T; N]
Borrows each element and returns an array of references with the same
size as self
.
§Example
let floats = [3.1, 2.7, -1.0];
let float_refs: [&f64; 3] = floats.each_ref();
assert_eq!(float_refs, [&3.1, &2.7, &-1.0]);
This method is particularly useful if combined with other methods, like
map
. This way, you can avoid moving the original
array if its elements are not Copy
.
let strings = ["Ferris".to_string(), "♥".to_string(), "Rust".to_string()];
let is_ascii = strings.each_ref().map(|s| s.is_ascii());
assert_eq!(is_ascii, [true, false, true]);
// We can still access the original array: it has not been moved.
assert_eq!(strings.len(), 3);
1.77.0 · sourcepub fn each_mut(&mut self) -> [&mut T; N]
pub fn each_mut(&mut self) -> [&mut T; N]
Borrows each element mutably and returns an array of mutable references
with the same size as self
.
§Example
let mut floats = [3.1, 2.7, -1.0];
let float_refs: [&mut f64; 3] = floats.each_mut();
*float_refs[0] = 0.0;
assert_eq!(float_refs, [&mut 0.0, &mut 2.7, &mut -1.0]);
assert_eq!(floats, [0.0, 2.7, -1.0]);
sourcepub fn split_array_ref<const M: usize>(&self) -> (&[T; M], &[T])
🔬This is a nightly-only experimental API. (split_array
)
pub fn split_array_ref<const M: usize>(&self) -> (&[T; M], &[T])
split_array
)Divides one array reference into two at an index.
The first will contain all indices from [0, M)
(excluding
the index M
itself) and the second will contain all
indices from [M, N)
(excluding the index N
itself).
§Panics
Panics if M > N
.
§Examples
#![feature(split_array)]
let v = [1, 2, 3, 4, 5, 6];
{
let (left, right) = v.split_array_ref::<0>();
assert_eq!(left, &[]);
assert_eq!(right, &[1, 2, 3, 4, 5, 6]);
}
{
let (left, right) = v.split_array_ref::<2>();
assert_eq!(left, &[1, 2]);
assert_eq!(right, &[3, 4, 5, 6]);
}
{
let (left, right) = v.split_array_ref::<6>();
assert_eq!(left, &[1, 2, 3, 4, 5, 6]);
assert_eq!(right, &[]);
}
sourcepub fn split_array_mut<const M: usize>(&mut self) -> (&mut [T; M], &mut [T])
🔬This is a nightly-only experimental API. (split_array
)
pub fn split_array_mut<const M: usize>(&mut self) -> (&mut [T; M], &mut [T])
split_array
)Divides one mutable array reference into two at an index.
The first will contain all indices from [0, M)
(excluding
the index M
itself) and the second will contain all
indices from [M, N)
(excluding the index N
itself).
§Panics
Panics if M > N
.
§Examples
#![feature(split_array)]
let mut v = [1, 0, 3, 0, 5, 6];
let (left, right) = v.split_array_mut::<2>();
assert_eq!(left, &mut [1, 0][..]);
assert_eq!(right, &mut [3, 0, 5, 6]);
left[1] = 2;
right[1] = 4;
assert_eq!(v, [1, 2, 3, 4, 5, 6]);
sourcepub fn rsplit_array_ref<const M: usize>(&self) -> (&[T], &[T; M])
🔬This is a nightly-only experimental API. (split_array
)
pub fn rsplit_array_ref<const M: usize>(&self) -> (&[T], &[T; M])
split_array
)Divides one array reference into two at an index from the end.
The first will contain all indices from [0, N - M)
(excluding
the index N - M
itself) and the second will contain all
indices from [N - M, N)
(excluding the index N
itself).
§Panics
Panics if M > N
.
§Examples
#![feature(split_array)]
let v = [1, 2, 3, 4, 5, 6];
{
let (left, right) = v.rsplit_array_ref::<0>();
assert_eq!(left, &[1, 2, 3, 4, 5, 6]);
assert_eq!(right, &[]);
}
{
let (left, right) = v.rsplit_array_ref::<2>();
assert_eq!(left, &[1, 2, 3, 4]);
assert_eq!(right, &[5, 6]);
}
{
let (left, right) = v.rsplit_array_ref::<6>();
assert_eq!(left, &[]);
assert_eq!(right, &[1, 2, 3, 4, 5, 6]);
}
sourcepub fn rsplit_array_mut<const M: usize>(&mut self) -> (&mut [T], &mut [T; M])
🔬This is a nightly-only experimental API. (split_array
)
pub fn rsplit_array_mut<const M: usize>(&mut self) -> (&mut [T], &mut [T; M])
split_array
)Divides one mutable array reference into two at an index from the end.
The first will contain all indices from [0, N - M)
(excluding
the index N - M
itself) and the second will contain all
indices from [N - M, N)
(excluding the index N
itself).
§Panics
Panics if M > N
.
§Examples
#![feature(split_array)]
let mut v = [1, 0, 3, 0, 5, 6];
let (left, right) = v.rsplit_array_mut::<4>();
assert_eq!(left, &mut [1, 0]);
assert_eq!(right, &mut [3, 0, 5, 6][..]);
left[1] = 2;
right[1] = 4;
assert_eq!(v, [1, 2, 3, 4, 5, 6]);
Trait Implementations§
source§impl AsMut<[u8]> for PieceArray
impl AsMut<[u8]> for PieceArray
source§impl AsRef<[u8]> for PieceArray
impl AsRef<[u8]> for PieceArray
source§impl Clone for PieceArray
impl Clone for PieceArray
source§fn clone(&self) -> PieceArray
fn clone(&self) -> PieceArray
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for PieceArray
impl Debug for PieceArray
source§impl Default for PieceArray
impl Default for PieceArray
source§impl Deref for PieceArray
impl Deref for PieceArray
source§impl DerefMut for PieceArray
impl DerefMut for PieceArray
source§impl From<&PieceArray> for &[u8; 1048672]
impl From<&PieceArray> for &[u8; 1048672]
source§fn from(value: &PieceArray) -> Self
fn from(value: &PieceArray) -> Self
source§impl From<&PieceArray> for Piece
impl From<&PieceArray> for Piece
source§fn from(value: &PieceArray) -> Self
fn from(value: &PieceArray) -> Self
source§impl From<&mut PieceArray> for &mut [u8; 1048672]
impl From<&mut PieceArray> for &mut [u8; 1048672]
source§fn from(value: &mut PieceArray) -> Self
fn from(value: &mut PieceArray) -> Self
source§impl Hash for PieceArray
impl Hash for PieceArray
source§impl Ord for PieceArray
impl Ord for PieceArray
source§fn cmp(&self, other: &PieceArray) -> Ordering
fn cmp(&self, other: &PieceArray) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl PartialEq for PieceArray
impl PartialEq for PieceArray
source§impl PartialOrd for PieceArray
impl PartialOrd for PieceArray
impl Copy for PieceArray
impl Eq for PieceArray
impl StructuralPartialEq for PieceArray
Auto Trait Implementations§
impl Freeze for PieceArray
impl RefUnwindSafe for PieceArray
impl Send for PieceArray
impl Sync for PieceArray
impl Unpin for PieceArray
impl UnwindSafe for PieceArray
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,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)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> 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
)