dalet-rs/src/typed.rs

103 lines
1.7 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>,
}
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-03 14:29:15 +03:00
Bl(NNBody, AlignArg),
Carousel(Vec<Tag>),
2024-08-03 14:29:15 +03:00
Code(TBody, TNArg),
Pre(TBody),
}
#[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,
}