New plans for macros
About to move them completely to stdlib
This commit is contained in:
@@ -20,11 +20,6 @@ pub trait Decode {
|
||||
pub trait Encode {
|
||||
/// Append an instance of the struct to the buffer
|
||||
fn encode<W: Write + ?Sized>(&self, write: &mut W);
|
||||
fn enc_vec(&self) -> Vec<u8> {
|
||||
let mut vec = Vec::new();
|
||||
self.encode(&mut vec);
|
||||
vec
|
||||
}
|
||||
}
|
||||
pub trait Coding: Encode + Decode + Clone {
|
||||
fn get_decoder<T>(map: impl Fn(Self) -> T + 'static) -> impl Fn(&mut dyn Read) -> T {
|
||||
@@ -87,7 +82,7 @@ nonzero_impl!(std::num::NonZeroI32);
|
||||
nonzero_impl!(std::num::NonZeroI64);
|
||||
nonzero_impl!(std::num::NonZeroI128);
|
||||
|
||||
impl<'a, T: Encode + 'a> Encode for &'a T {
|
||||
impl<'a, T: Encode + ?Sized> Encode for &'a T {
|
||||
fn encode<W: Write + ?Sized>(&self, write: &mut W) { (**self).encode(write) }
|
||||
}
|
||||
impl<T: Decode + FloatCore> Decode for NotNan<T> {
|
||||
|
||||
@@ -16,3 +16,9 @@ pub fn read_exact<R: Read + ?Sized>(read: &mut R, bytes: &'static [u8]) {
|
||||
read.read_exact(&mut data).expect("Failed to read bytes");
|
||||
assert_eq!(&data, bytes, "Wrong bytes")
|
||||
}
|
||||
|
||||
pub fn enc_vec(enc: &impl Encode) -> Vec<u8> {
|
||||
let mut vec = Vec::new();
|
||||
enc.encode(&mut vec);
|
||||
vec
|
||||
}
|
||||
@@ -4,6 +4,6 @@ mod hierarchy;
|
||||
mod relations;
|
||||
|
||||
pub use coding::{Coding, Decode, Encode};
|
||||
pub use helpers::{encode_enum, read_exact, write_exact};
|
||||
pub use helpers::{encode_enum, read_exact, write_exact, enc_vec};
|
||||
pub use hierarchy::{Extends, InHierarchy, TLBool, TLFalse, TLTrue, UnderRoot};
|
||||
pub use relations::{Channel, MsgSet, Request};
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
use super::coding::{Coding, Encode};
|
||||
use crate::helpers::enc_vec;
|
||||
|
||||
use super::coding::Coding;
|
||||
|
||||
pub trait Request: Coding + Sized + Send + 'static {
|
||||
type Response: Coding + Send + 'static;
|
||||
fn respond(&self, rep: Self::Response) -> Vec<u8> { rep.enc_vec() }
|
||||
fn respond(&self, rep: Self::Response) -> Vec<u8> { enc_vec(&rep) }
|
||||
}
|
||||
|
||||
pub trait Channel: 'static {
|
||||
|
||||
Reference in New Issue
Block a user