pub trait Transcribable: GenTranscribable {
const LENGTH_NUM_BYTES: usize = u32::NUM_BYTES;
// Required method
fn get_num_bytes(&self) -> usize;
// Provided methods
fn read_num_bytes(bytes: &[u8]) -> usize { ... }
fn read_transcription_bytes_subset(bytes: &[u8]) -> (Self, &[u8]) { ... }
fn write_transcription_bytes_subset<'a>(
&self,
buf: &'a mut [u8],
) -> &'a mut [u8] ⓘ { ... }
}Expand description
Trait for types that can be transcribed to and from a byte representation. Byte order is not specified, but it must be portable across platforms.
Provided Associated Constants§
Sourceconst LENGTH_NUM_BYTES: usize = u32::NUM_BYTES
const LENGTH_NUM_BYTES: usize = u32::NUM_BYTES
Number of bytes required to represent length of this type, could be zero if known in advance.
Required Methods§
Sourcefn get_num_bytes(&self) -> usize
fn get_num_bytes(&self) -> usize
Returns the number of bytes required to represent this type.
The buffer passed to write_transcription_bytes should be exactly the
length returned by this function.
Provided Methods§
Sourcefn read_num_bytes(bytes: &[u8]) -> usize
fn read_num_bytes(bytes: &[u8]) -> usize
Read number of bytes required to represent this type.
The buffer must be exactly LENGTH_NUM_BYTES long.
The buffer passed to read_transcription_bytes should be exactly the
length returned by this function.
Sourcefn read_transcription_bytes_subset(bytes: &[u8]) -> (Self, &[u8])
fn read_transcription_bytes_subset(bytes: &[u8]) -> (Self, &[u8])
Reads an instance of this type from the beginning of the byte slice, and returns the instance along with the remaining byte slice.
Sourcefn write_transcription_bytes_subset<'a>(
&self,
buf: &'a mut [u8],
) -> &'a mut [u8] ⓘ
fn write_transcription_bytes_subset<'a>( &self, buf: &'a mut [u8], ) -> &'a mut [u8] ⓘ
Writes this instance, prefixed by length, into the beginning of the byte buffer, and returns the remaining byte buffer.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl Transcribable for BoxedUint
impl Transcribable for BoxedUint
Source§const LENGTH_NUM_BYTES: usize = 1
const LENGTH_NUM_BYTES: usize = 1
Up to 255 bytes - so up to 2040 bits - should be plenty.