Struct subspace_core_primitives::crypto::Scalar
source · pub struct Scalar(/* private fields */);
Expand description
Representation of a single BLS12-381 scalar value.
Implementations§
source§impl Scalar
impl Scalar
sourcepub const SAFE_BYTES: usize = 31usize
pub const SAFE_BYTES: usize = 31usize
How many full bytes can be stored in BLS12-381 scalar (for instance before encoding). It is actually 254 bits, but bits are mut harder to work with and likely not worth it.
NOTE: After encoding more bytes can be used, so don’t rely on this as the max number of bytes stored within at all times!
sourcepub const FULL_BYTES: usize = 32usize
pub const FULL_BYTES: usize = 32usize
How many bytes Scalar contains physically, use Self::SAFE_BYTES
for the amount of data
that you can put into it safely (for instance before encoding).
sourcepub fn try_to_safe_bytes(&self) -> Option<[u8; 31]>
pub fn try_to_safe_bytes(&self) -> Option<[u8; 31]>
Convert scalar into safe bytes, returns None
if not possible to convert due to larger
internal value
sourcepub fn slice_to_repr(value: &[Self]) -> &[FsFr]
pub fn slice_to_repr(value: &[Self]) -> &[FsFr]
Convenient conversion from slice of scalar to underlying representation for efficiency purposes.
sourcepub fn slice_from_repr(value: &[FsFr]) -> &[Self]
pub fn slice_from_repr(value: &[FsFr]) -> &[Self]
Convenient conversion from slice of underlying representation to scalar for efficiency purposes.
sourcepub fn slice_option_to_repr(value: &[Option<Self>]) -> &[Option<FsFr>]
pub fn slice_option_to_repr(value: &[Option<Self>]) -> &[Option<FsFr>]
Convenient conversion from slice of optional scalar to underlying representation for efficiency purposes.
sourcepub fn slice_option_from_repr(value: &[Option<FsFr>]) -> &[Option<Self>]
pub fn slice_option_from_repr(value: &[Option<FsFr>]) -> &[Option<Self>]
Convenient conversion from slice of optional underlying representation to scalar for efficiency purposes.
sourcepub fn slice_mut_to_repr(value: &mut [Self]) -> &mut [FsFr]
pub fn slice_mut_to_repr(value: &mut [Self]) -> &mut [FsFr]
Convenient conversion from mutable slice of scalar to underlying representation for efficiency purposes.
sourcepub fn slice_mut_from_repr(value: &mut [FsFr]) -> &mut [Self]
pub fn slice_mut_from_repr(value: &mut [FsFr]) -> &mut [Self]
Convenient conversion from mutable slice of underlying representation to scalar for efficiency purposes.
sourcepub fn slice_option_mut_to_repr(
value: &mut [Option<Self>],
) -> &mut [Option<FsFr>]
pub fn slice_option_mut_to_repr( value: &mut [Option<Self>], ) -> &mut [Option<FsFr>]
Convenient conversion from optional mutable slice of scalar to underlying representation for efficiency purposes.
sourcepub fn slice_option_mut_from_repr(
value: &mut [Option<FsFr>],
) -> &mut [Option<Self>]
pub fn slice_option_mut_from_repr( value: &mut [Option<FsFr>], ) -> &mut [Option<Self>]
Convenient conversion from optional mutable slice of underlying representation to scalar for efficiency purposes.
sourcepub fn vec_to_repr(value: Vec<Self>) -> Vec<FsFr>
pub fn vec_to_repr(value: Vec<Self>) -> Vec<FsFr>
Convenient conversion from vector of scalar to underlying representation for efficiency purposes.
sourcepub fn vec_from_repr(value: Vec<FsFr>) -> Vec<Self>
pub fn vec_from_repr(value: Vec<FsFr>) -> Vec<Self>
Convenient conversion from vector of underlying representation to scalar for efficiency purposes.
Trait Implementations§
source§impl Decode for Scalar
impl Decode for Scalar
source§fn decode<I: Input>(input: &mut I) -> Result<Self, Error>
fn decode<I: Input>(input: &mut I) -> Result<Self, Error>
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 Scalar
impl<'de> Deserialize<'de> for Scalar
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 Scalar
impl Encode for Scalar
source§fn size_hint(&self) -> usize
fn size_hint(&self) -> usize
source§fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R
source§fn encoded_size(&self) -> usize
fn encoded_size(&self) -> usize
source§impl MaxEncodedLen for Scalar
impl MaxEncodedLen for Scalar
source§fn max_encoded_len() -> usize
fn max_encoded_len() -> usize
source§impl Ord for Scalar
impl Ord for Scalar
source§impl PartialOrd for Scalar
impl PartialOrd for Scalar
impl Copy for Scalar
impl EncodeLike for Scalar
impl Eq for Scalar
impl StructuralPartialEq for Scalar
Auto Trait Implementations§
impl Freeze for Scalar
impl RefUnwindSafe for Scalar
impl Send for Scalar
impl Sync for Scalar
impl Unpin for Scalar
impl UnwindSafe for Scalar
Blanket Implementations§
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§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§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> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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.