dalet-rs/src/typed.rs

114 lines
1.9 KiB
Rust
Raw Normal View History

2024-08-03 12:47:33 +03:00
use enum_procs::AutoFrom;
use num_enum::TryFromPrimitive;
2024-08-05 18:43:18 +03:00
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Page {
pub data: Vec<Tag>,
}
2024-08-06 10:16:24 +03:00
impl Page {
pub fn new(data: Vec<Tag>) -> Self {
Self { data }
}
}
2024-08-05 18:43:18 +03:00
pub struct ConversionError;
2024-08-03 12:47:33 +03:00
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Tag {
2024-08-02 22:35:49 +03:00
El(NNBody),
2024-08-03 14:29:15 +03:00
H(TBody, Hl),
2024-08-02 22:35:49 +03:00
P(NNBody),
Br,
Ul(Vec<Tag>),
Ol(Vec<Tag>),
2024-08-03 14:29:15 +03:00
Row(Vec<Tag>, AlignArg),
Link(Body, TArg),
Navlink(Body, TArg),
Btn(Body, TArg),
Navbtn(Body, TArg),
Img(TArg),
Table(Vec<Tag>),
Tcol(Vec<Tag>),
Tpcol(Vec<Tag>),
Hr,
2024-08-03 14:29:15 +03:00
B(TBody),
I(TBody),
2024-08-02 22:35:49 +03:00
Bq(NNBody),
Footlnk(NNArg),
2024-08-03 14:29:15 +03:00
Footn(TBody, NNArg),
2024-08-02 22:35:49 +03:00
A(NNArg),
2024-08-03 14:29:15 +03:00
S(TBody),
Sup(TBody),
Sub(TBody),
2024-08-02 22:35:49 +03:00
Disc(NNBody),
2024-08-07 15:13:16 +03:00
Block(NNBody, AlignArg),
Carousel(Vec<Tag>),
2024-08-03 14:29:15 +03:00
Code(TBody, TNArg),
Pre(TBody),
2024-08-07 15:13:16 +03:00
Meta(TBody, TArg),
2024-08-03 14:29:15 +03:00
}
#[derive(AutoFrom, Debug, Clone, PartialEq, Eq)]
pub enum Body {
Text(String),
Tags(Vec<Tag>),
Null,
}
#[derive(AutoFrom, Debug, Clone, PartialEq, Eq)]
pub enum NNBody {
Text(String),
Tags(Vec<Tag>),
}
/// Text body
pub type TBody = String;
#[derive(AutoFrom, Debug, Clone, PartialEq, Eq)]
pub enum Arg {
Text(String),
Number(u8),
Null,
}
#[derive(AutoFrom, Debug, Clone, PartialEq, Eq)]
pub enum TNArg {
Text(String),
Null,
}
/// Text argument
pub type TArg = String;
#[derive(AutoFrom, Debug, Clone, PartialEq, Eq)]
/// Not null argument
pub enum NNArg {
Text(String),
Number(u8),
}
#[derive(Debug, Clone, PartialEq, Eq, TryFromPrimitive)]
#[repr(u8)]
pub enum AlignArg {
Start,
Center,
End,
}
#[derive(Debug, Clone, PartialEq, Eq, TryFromPrimitive)]
#[repr(u8)]
/// Heading level
pub enum Hl {
One = 1,
Two,
Three,
Four,
Five,
Six,
}
2024-08-07 15:13:16 +03:00
pub trait ResolveTitle {
2024-08-07 15:23:18 +03:00
fn resolve_title(&self) -> Option<String>;
2024-08-07 15:13:16 +03:00
}