mirror of
https://github.com/TxtDot/dalet-rs.git
synced 2024-11-21 16:26:21 +03:00
refactor: rename root to page
This commit is contained in:
parent
5058bb812b
commit
a9f7d54ee1
5 changed files with 20 additions and 20 deletions
|
@ -3,7 +3,7 @@ use num_enum::TryFromPrimitive;
|
|||
use serde::{Deserialize, Serialize};
|
||||
use serde_repr::{Deserialize_repr, Serialize_repr};
|
||||
|
||||
pub type Root = Vec<Tag>;
|
||||
pub type Page = Vec<Tag>;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Tag {
|
||||
|
@ -98,7 +98,7 @@ pub trait IsNull {
|
|||
fn is_null(&self) -> bool;
|
||||
}
|
||||
|
||||
pub trait ToDaletlRoot {
|
||||
/// Convert to daletl root
|
||||
fn to_dl_root(self) -> Root;
|
||||
pub trait ToDaletlPage {
|
||||
/// Convert to daletl Page
|
||||
fn to_dl_page(self) -> Page;
|
||||
}
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
use crate::daletl::{Argument, Body, IsNull, Tag, Tid};
|
||||
use crate::daletl::{Argument, Body, IsNull, Page, Tag, Tid};
|
||||
|
||||
use super::{DaletPackError, TypeId};
|
||||
|
||||
pub fn encode(root: &Vec<Tag>) -> Result<Vec<u8>, DaletPackError> {
|
||||
Ok(zstd::bulk::compress(&encode_no_compress(root)?, 5)
|
||||
pub fn encode(page: &Page) -> Result<Vec<u8>, DaletPackError> {
|
||||
Ok(zstd::bulk::compress(&encode_no_compress(page)?, 5)
|
||||
.map_err(|_| DaletPackError::ZstdCompressError)?)
|
||||
}
|
||||
|
||||
pub fn encode_no_compress(root: &Vec<Tag>) -> Result<Vec<u8>, DaletPackError> {
|
||||
if root.len() > 2usize.pow(32) {
|
||||
return Err(DaletPackError::RootMaxSizeExceeded);
|
||||
pub fn encode_no_compress(page: &Page) -> Result<Vec<u8>, DaletPackError> {
|
||||
if page.len() > 2usize.pow(32) {
|
||||
return Err(DaletPackError::PageMaxSizeExceeded);
|
||||
}
|
||||
|
||||
let mut bv: Vec<u8> = Vec::new();
|
||||
|
||||
for tag in root {
|
||||
for tag in page {
|
||||
write_tag(&mut bv, tag)?;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ use num_enum::TryFromPrimitive;
|
|||
pub enum DaletPackError {
|
||||
StrMaxSizeExceeded,
|
||||
ArrMaxSizeExceeded,
|
||||
RootMaxSizeExceeded,
|
||||
PageMaxSizeExceeded,
|
||||
ZstdCompressError,
|
||||
|
||||
WriteNullBody,
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
use enum_procs::AutoFrom;
|
||||
use num_enum::TryFromPrimitive;
|
||||
|
||||
use crate::daletl::{self, t_new, Tid, ToDaletlRoot};
|
||||
use crate::daletl::{self, t_new, Tid, ToDaletlPage};
|
||||
|
||||
const NB: daletl::Body = daletl::Body::Null;
|
||||
const NA: daletl::Argument = daletl::Argument::Null;
|
||||
|
||||
pub type Root = Vec<Tag>;
|
||||
pub type Page = Vec<Tag>;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum Tag {
|
||||
|
@ -208,8 +208,8 @@ impl From<Vec<Tag>> for daletl::Body {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToDaletlRoot for Root {
|
||||
fn to_dl_root(self) -> daletl::Root {
|
||||
impl ToDaletlPage for Page {
|
||||
fn to_dl_page(self) -> daletl::Page {
|
||||
self.into_iter().map(|tag| tag.into()).collect()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use dalet::{
|
||||
daletl::ToDaletlRoot,
|
||||
daletl::ToDaletlPage,
|
||||
daletpack::*,
|
||||
typed::{
|
||||
Body, Hl, NNBody, Root, TNArgument,
|
||||
Body, Hl, NNBody, Page, TNArgument,
|
||||
Tag::{self, *},
|
||||
},
|
||||
};
|
||||
|
@ -35,7 +35,7 @@ pub fn compress_zlib(data: &Vec<u8>) -> std::io::Result<Vec<u8>> {
|
|||
|
||||
#[test]
|
||||
fn bench() {
|
||||
let page: Root = vec![
|
||||
let page: Page = vec![
|
||||
H("I am heading".into(), Hl::One),
|
||||
H("Heading 2".into(), Hl::Two),
|
||||
El(vec![
|
||||
|
@ -81,7 +81,7 @@ fn bench() {
|
|||
]),
|
||||
];
|
||||
|
||||
let dalet_page = page.to_dl_root();
|
||||
let dalet_page = page.to_dl_page();
|
||||
|
||||
let markdown = iprint!("Markdown", include_str!("./bench.md").as_bytes().to_vec());
|
||||
let daletpack = iprint!("Daletpack", encode_no_compress(&dalet_page).unwrap());
|
||||
|
|
Loading…
Add table
Reference in a new issue