Moved Bytes interface to dcb-bytes crate.

Instead of implementing `Bytes for Option<T>`, a proxy is now used, as `dcb-bytes` is in a separate crate.
This commit is contained in:
2020-09-20 02:34:39 +01:00
parent 152c8250ff
commit 2a39f8b438
21 changed files with 261 additions and 103 deletions

39
dcb-bytes/src/bytes.rs Normal file
View File

@@ -0,0 +1,39 @@
//! Interface for converting various structures to and from bytes
// Imports
use std::error::Error;
/// Conversions to and from bytes for the game file
pub trait Bytes
where
Self: Sized,
{
/// The type of array required by this structure
type ByteArray: ByteArray;
/// The error type used for the operation
type FromError: Error;
/// The error type used for the operation
type ToError: Error;
/// Constructs this structure from `bytes`
fn from_bytes(bytes: &Self::ByteArray) -> Result<Self, Self::FromError>;
/// Writes this structure to `bytes`
fn to_bytes(&self, bytes: &mut Self::ByteArray) -> Result<(), Self::ToError>;
}
/// A trait for restricting `Bytes::ByteArray`
pub trait ByteArray {
/// Size of this array
const SIZE: usize;
}
impl<const N: usize> ByteArray for [u8; N] {
const SIZE: usize = N;
}
impl ByteArray for u8 {
const SIZE: usize = 1;
}