pub trait Flags:
Default
+ Clone
+ Copy
+ Sized {
const BIT_SIZE: usize;
// Required methods
fn u8_bitmask(&self) -> u8;
fn from_u8(value: u8) -> Option<Self>;
// Provided method
fn from_u8_remove_flags(value: &mut u8) -> Option<Self> { ... }
}Expand description
Represents metadata to be appended to an object’s serialization.
For example, when serializing elliptic curve points, one can
use a Flag to represent whether the serialization is the point
at infinity, or whether the y coordinate is positive or not.
These bits will be appended to the end of the point’s serialization,
or included in a new byte, depending on space available.
This is meant to be provided to CanonicalSerializeWithFlags and
CanonicalDeserializeWithFlags
Required Associated Constants§
Required Methods§
Sourcefn u8_bitmask(&self) -> u8
fn u8_bitmask(&self) -> u8
Returns a bit mask corresponding to self.
For example, if Self contains two variants, there are just two possible
bit masks: 0 and 1 << 7.
Sourcefn from_u8(value: u8) -> Option<Self>
fn from_u8(value: u8) -> Option<Self>
Tries to read Self from value. Should return None if the
Self::BIT_SIZE most-significant bits of value do not correspond to
those generated by u8_bitmask.
That is, this method ignores all but the top Self::BIT_SIZE bits, and
decides whether these top bits correspond to a bitmask output by
u8_bitmask.
Provided Methods§
Sourcefn from_u8_remove_flags(value: &mut u8) -> Option<Self>
fn from_u8_remove_flags(value: &mut u8) -> Option<Self>
Convenience method that reads Self from value, just like Self::from_u8,
but additionally zeroes out the bits corresponding to the resulting flag
in value. If Self::from_u8(*value) would return None, then this
method should not modify value.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".