refactor: move traits to daletl

This commit is contained in:
Artemy Egorov 2024-08-02 22:09:12 +03:00
parent accf9aae58
commit 4cc99ce163
4 changed files with 25 additions and 24 deletions

View file

@ -1,6 +1,6 @@
use num_enum::TryFromPrimitive; use num_enum::TryFromPrimitive;
use crate::daletl::{self, t_new, Tid}; use crate::daletl::{self, t_new, Tid, ToDaletl, ToDaletlArgument, ToDaletlBody, ToDaletlTag};
const NB: daletl::Body = daletl::Body::Null; const NB: daletl::Body = daletl::Body::Null;
const NA: daletl::Argument = daletl::Argument::Null; const NA: daletl::Argument = daletl::Argument::Null;
@ -39,14 +39,6 @@ pub enum Tag {
Pre(String), Pre(String),
} }
pub trait ToDaletl {
fn to_daletl(self) -> Vec<daletl::Tag>;
}
pub trait ToDaletlTag {
fn to_daletl_tag(self) -> daletl::Tag;
}
impl ToDaletlTag for Tag { impl ToDaletlTag for Tag {
fn to_daletl_tag(self) -> daletl::Tag { fn to_daletl_tag(self) -> daletl::Tag {
match self { match self {
@ -84,14 +76,6 @@ impl ToDaletlTag for Tag {
} }
} }
pub trait ToDaletlBody {
fn to_daletl_body(self) -> daletl::Body;
}
pub trait ToDaletlArgument {
fn to_daletl_argument(self) -> daletl::Argument;
}
#[derive(Debug, Clone, PartialEq, Eq, TryFromPrimitive)] #[derive(Debug, Clone, PartialEq, Eq, TryFromPrimitive)]
#[repr(u8)] #[repr(u8)]
pub enum HeadingLevel { pub enum HeadingLevel {

View file

@ -21,10 +21,6 @@ pub fn t_new(id: Tid, body: Body, argument: Argument) -> Tag {
Tag::new(id, body, argument) Tag::new(id, body, argument)
} }
pub trait IsNull {
fn is_null(&self) -> bool;
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(untagged)] #[serde(untagged)]
pub enum Body { pub enum Body {
@ -94,3 +90,23 @@ pub enum Tid {
Code, Code,
Pre, Pre,
} }
pub trait IsNull {
fn is_null(&self) -> bool;
}
pub trait ToDaletl {
fn to_daletl(self) -> Vec<Tag>;
}
pub trait ToDaletlTag {
fn to_daletl_tag(self) -> Tag;
}
pub trait ToDaletlBody {
fn to_daletl_body(self) -> Body;
}
pub trait ToDaletlArgument {
fn to_daletl_argument(self) -> Argument;
}

View file

@ -1,9 +1,10 @@
use dalet::{ use dalet::{
abstractions::{Body, HeadingLevel, NotNullBody, Tag, TextOrNullArgument, ToDaletl}, abstractions::{Body, HeadingLevel, NotNullBody, Tag, TextOrNullArgument},
daletl::ToDaletl,
daletpack::*, daletpack::*,
}; };
use flate2::Compression; use flate2::Compression;
use std::io::{read_to_string, Write}; use std::io::Write;
#[macro_export] #[macro_export]
macro_rules! iprint { macro_rules! iprint {

View file

@ -3,7 +3,7 @@
=> gemini://example.com A supremely cool Gemini capsule => gemini://example.com A supremely cool Gemini capsule
=> sftp://example.com => sftp://example.com
Hi This is paragraph
=>https://example.com A cool website =>https://example.com A cool website
=>gopher://example.com An even cooler gopherhole =>gopher://example.com An even cooler gopherhole