diff options
author | 2021-05-16 22:16:11 -0700 | |
---|---|---|
committer | 2021-05-16 22:38:43 -0700 | |
commit | ddeced347b45f66e8dfdbaff0cae6da50a600539 (patch) | |
tree | 7c9bfe080710d477cd0bb8dfea13ae7ac6b63040 /src/models.rs | |
parent | bb1f98f8e126658a658409fd1b317ae66148cfa6 (diff) | |
download | notion-ddeced347b45f66e8dfdbaff0cae6da50a600539.tar.gz notion-ddeced347b45f66e8dfdbaff0cae6da50a600539.tar.zst notion-ddeced347b45f66e8dfdbaff0cae6da50a600539.zip |
all blocks
Diffstat (limited to 'src/models.rs')
-rw-r--r-- | src/models.rs | 88 |
1 files changed, 56 insertions, 32 deletions
diff --git a/src/models.rs b/src/models.rs index cb29e00..9f2cd14 100644 --- a/src/models.rs +++ b/src/models.rs @@ -135,38 +135,6 @@ pub struct Page { parent: Parent, } -impl Identifiable for String { - type Type = String; - - fn id(&self) -> &Self::Type { - self - } -} - -#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Hash, Clone)] -#[serde(transparent)] -pub struct BlockId(String); - -impl BlockId { - pub fn id(&self) -> &str { - &self.0 - } -} - -impl Identifiable for BlockId { - type Type = BlockId; - - fn id(&self) -> &Self::Type { - self - } -} - -impl Display for BlockId { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - self.0.fmt(f) - } -} - #[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)] #[serde(rename_all = "snake_case")] pub enum BlockType { @@ -268,6 +236,34 @@ pub enum Block { Unsupported {} } +impl Identifiable for Block { + type Type = BlockId; + + fn id(&self) -> &Self::Type { + match self { + Block::Paragraph { common, paragraph: _ } => &common.id, + Block::Heading1 { common, heading_1: _} => &common.id, + Block::Heading2 { common, heading_2: _} => &common.id, + Block::Heading3 { common, heading_3: _} => &common.id, + Block::BulletedListItem { common, bulleted_list_item: _} => &common.id, + Block::NumberedListItem { common, numbered_list_item: _} => &common.id, + Block::ToDo { common, to_do: _ } => &common.id, + Block::Toggle { common, toggle: _} => &common.id, + Block::ChildPage { common, child_page: _} => &common.id, + Block::Unsupported {} => { panic!("Trying to reference identifier for unsupported block!") } + } + + } +} + +impl Identifiable for Page { + type Type = PageId; + + fn id(&self) -> &Self::Type { + &self.id + } +} + #[derive(Eq, Serialize, Deserialize, Clone, Debug, PartialEq)] #[serde(tag = "object")] #[serde(rename_all = "snake_case")] @@ -294,6 +290,34 @@ pub enum Object { }, } +#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Hash, Clone)] +#[serde(transparent)] +pub struct BlockId(String); + +impl BlockId { + pub fn id(&self) -> &str { + &self.0 + } + + pub fn from(page_id: &PageId) -> Self { + BlockId(page_id.clone().0) + } +} + +impl Identifiable for BlockId { + type Type = BlockId; + + fn id(&self) -> &Self::Type { + self + } +} + +impl Display for BlockId { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + self.0.fmt(f) + } +} + impl Object { pub fn is_database(&self) -> bool { matches!(self, Object::Database { .. }) |