From a9f7d54ee12f545e3d0d95481d16ffdd07a102a5 Mon Sep 17 00:00:00 2001 From: Artemy Egorov Date: Sat, 3 Aug 2024 12:56:08 +0300 Subject: [PATCH] refactor: rename root to page --- src/daletl.rs | 8 ++++---- src/daletpack/encode.rs | 14 +++++++------- src/daletpack/types.rs | 2 +- src/typed.rs | 8 ++++---- tests/bench.rs | 8 ++++---- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/daletl.rs b/src/daletl.rs index b95d07a..47ae849 100644 --- a/src/daletl.rs +++ b/src/daletl.rs @@ -3,7 +3,7 @@ use num_enum::TryFromPrimitive; use serde::{Deserialize, Serialize}; use serde_repr::{Deserialize_repr, Serialize_repr}; -pub type Root = Vec; +pub type Page = Vec; #[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; } diff --git a/src/daletpack/encode.rs b/src/daletpack/encode.rs index df27c2e..af369ea 100644 --- a/src/daletpack/encode.rs +++ b/src/daletpack/encode.rs @@ -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) -> Result, DaletPackError> { - Ok(zstd::bulk::compress(&encode_no_compress(root)?, 5) +pub fn encode(page: &Page) -> Result, DaletPackError> { + Ok(zstd::bulk::compress(&encode_no_compress(page)?, 5) .map_err(|_| DaletPackError::ZstdCompressError)?) } -pub fn encode_no_compress(root: &Vec) -> Result, DaletPackError> { - if root.len() > 2usize.pow(32) { - return Err(DaletPackError::RootMaxSizeExceeded); +pub fn encode_no_compress(page: &Page) -> Result, DaletPackError> { + if page.len() > 2usize.pow(32) { + return Err(DaletPackError::PageMaxSizeExceeded); } let mut bv: Vec = Vec::new(); - for tag in root { + for tag in page { write_tag(&mut bv, tag)?; } diff --git a/src/daletpack/types.rs b/src/daletpack/types.rs index edd6fc0..c6fc344 100644 --- a/src/daletpack/types.rs +++ b/src/daletpack/types.rs @@ -4,7 +4,7 @@ use num_enum::TryFromPrimitive; pub enum DaletPackError { StrMaxSizeExceeded, ArrMaxSizeExceeded, - RootMaxSizeExceeded, + PageMaxSizeExceeded, ZstdCompressError, WriteNullBody, diff --git a/src/typed.rs b/src/typed.rs index 1fb150d..57e99aa 100644 --- a/src/typed.rs +++ b/src/typed.rs @@ -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; +pub type Page = Vec; #[derive(Debug, Clone, PartialEq, Eq)] pub enum Tag { @@ -208,8 +208,8 @@ impl From> 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() } } diff --git a/tests/bench.rs b/tests/bench.rs index 5f10d41..5086fef 100644 --- a/tests/bench.rs +++ b/tests/bench.rs @@ -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) -> std::io::Result> { #[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());