atomic::array
This commit is contained in:
parent
8c033ed044
commit
7d82983ce5
@ -1,6 +1,7 @@
|
||||
//! This module allows to describe a primitive subset of [Mentionable] types, [Atomic]s,
|
||||
//! simple static types, which are completely [Context]-independent.
|
||||
|
||||
pub mod array;
|
||||
pub mod atomic_object;
|
||||
pub mod au64;
|
||||
pub mod boolean;
|
||||
|
61
src/rstd/atomic/array.rs
Normal file
61
src/rstd/atomic/array.rs
Normal file
@ -0,0 +1,61 @@
|
||||
use crate::rstd::inlining::*;
|
||||
|
||||
use super::*;
|
||||
|
||||
impl<const N: usize> Serializable for [u8; N] {
|
||||
fn serialize(&self, serializer: &mut dyn Serializer) {
|
||||
serializer.write(self)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum ArrayParseError {
|
||||
Eof,
|
||||
ExtraData(usize),
|
||||
}
|
||||
|
||||
impl Display for ArrayParseError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Eof => write!(f, "encountered EOF write parsing an array."),
|
||||
Self::ExtraData(length) => write!(
|
||||
f,
|
||||
"encountered extra data of length {length} while parsing an array.",
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Error for ArrayParseError {}
|
||||
|
||||
impl From<&[u8]> for ArrayParseError {
|
||||
fn from(_value: &[u8]) -> Self {
|
||||
Self::Eof
|
||||
}
|
||||
}
|
||||
|
||||
impl<const N: usize> Atomic for [u8; N] {
|
||||
type AParseError = ArrayParseError;
|
||||
|
||||
fn a_deserialize(inlining: impl Inlining) -> AParseResult<Self> {
|
||||
Self::a_ideserialize(inlining).seal()
|
||||
}
|
||||
|
||||
fn a_extend(self, tail: &[u8]) -> AParseResult<Self> {
|
||||
Err(Self::a_extension_error(tail))
|
||||
}
|
||||
}
|
||||
|
||||
impl<const N: usize> InlineableAtomic for [u8; N] {
|
||||
fn a_extension_error(tail: &[u8]) -> Self::AParseError {
|
||||
ArrayParseError::ExtraData(tail.len())
|
||||
}
|
||||
|
||||
fn a_ideserialize<D: Inlining>(inlining: D) -> ADParseResult<Self, D> {
|
||||
inlining.iread_n_const::<N>(|slice| ArrayParseError::from(slice))
|
||||
}
|
||||
}
|
||||
|
||||
impl<const N: usize> ConstSizeAtomic for [u8; N] {
|
||||
const SIZE: usize = N;
|
||||
}
|
Loading…
Reference in New Issue
Block a user