Compare commits
2 Commits
73c4458f23
...
45dbf1a13c
Author | SHA1 | Date | |
---|---|---|---|
45dbf1a13c | |||
1ad533765f |
@ -2,6 +2,7 @@
|
|||||||
//! simple static types, which are completely [Context]-independent.
|
//! simple static types, which are completely [Context]-independent.
|
||||||
|
|
||||||
pub mod atomic_object;
|
pub mod atomic_object;
|
||||||
|
pub mod au64;
|
||||||
pub mod boolean;
|
pub mod boolean;
|
||||||
pub mod plain;
|
pub mod plain;
|
||||||
|
|
||||||
|
50
src/rstd/atomic/au64.rs
Normal file
50
src/rstd/atomic/au64.rs
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
use crate::rstd::inlining::*;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
impl Serializable for u64 {
|
||||||
|
fn serialize(&self, serializer: &mut dyn Serializer) {
|
||||||
|
serializer.write(&self.to_le_bytes());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
|
pub enum IntParseError {
|
||||||
|
Eof,
|
||||||
|
ExtraData(usize),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for IntParseError {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
Self::Eof => f.write_fmt(format_args!("encountered EOF write parsing an integer.")),
|
||||||
|
Self::ExtraData(length) => f.write_fmt(format_args!(
|
||||||
|
"encountered extra data of length {length} while parsing an integer.",
|
||||||
|
)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Error for IntParseError {}
|
||||||
|
|
||||||
|
impl From<&[u8]> for IntParseError {
|
||||||
|
fn from(_value: &[u8]) -> Self {
|
||||||
|
Self::Eof
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Atomic for u64 {
|
||||||
|
type AParseError = IntParseError;
|
||||||
|
|
||||||
|
fn a_deserialize(deserializer: &mut dyn Deserializer) -> Result<Self, Self::AParseError> {
|
||||||
|
Ok(u64::from_le_bytes(deserializer.read_n_const::<8>()?))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn a_unexpected_tail(tail: &[u8]) -> Self::AParseError {
|
||||||
|
IntParseError::ExtraData(tail.len())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ConstSizeAtomic for u64 {
|
||||||
|
const SIZE: usize = 8;
|
||||||
|
}
|
@ -21,15 +21,12 @@ pub enum BooleanParseError {
|
|||||||
impl Display for BooleanParseError {
|
impl Display for BooleanParseError {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
BooleanParseError::OutOfBounds(value) => {
|
Self::OutOfBounds(value) => {
|
||||||
f.write_fmt(format_args!("boolean value out of bounds: {}.", value))
|
f.write_fmt(format_args!("boolean value out of bounds: {}.", value))
|
||||||
}
|
}
|
||||||
BooleanParseError::Eof => {
|
Self::Eof => f.write_fmt(format_args!("encountered EOF write parsing a boolean.")),
|
||||||
f.write_fmt(format_args!("encountered EOF write parsing a boolean."))
|
Self::ExtraData(length) => f.write_fmt(format_args!(
|
||||||
}
|
"encountered extra data of length {length} while parsing a boolean.",
|
||||||
BooleanParseError::ExtraData(length) => f.write_fmt(format_args!(
|
|
||||||
"encountered extra data of length {} while parsing a boolean",
|
|
||||||
length
|
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user