feat: start flat encoder

This commit is contained in:
rvcas 2022-05-21 20:13:49 -04:00
parent 6d5057dff4
commit dbc2772e63
No known key found for this signature in database
GPG Key ID: C09B64E263F7D68C
2 changed files with 30 additions and 0 deletions

29
src/flat.rs Normal file
View File

@ -0,0 +1,29 @@
pub trait Encode {
fn encode(&self, e: &mut Encoder) -> Result<(), String>;
}
pub struct Encoder {
pub bytes: Vec<u8>,
}
impl Default for Encoder {
fn default() -> Self {
Self::new()
}
}
impl Encoder {
pub fn new() -> Encoder {
Encoder { bytes: Vec::new() }
}
/// Encode any type that implements [`Encode`].
pub fn encode<T: Encode>(&mut self, x: T) -> Result<&mut Self, String> {
x.encode(self)?;
Ok(self)
}
pub fn u8(&mut self, x: u8) -> Result<&mut Self, String> {
todo!()
}
}

View File

@ -1,6 +1,7 @@
pub mod ast; pub mod ast;
pub mod builtins; pub mod builtins;
pub mod cli; pub mod cli;
pub mod flat;
pub mod parser; pub mod parser;
#[macro_use] #[macro_use]