diff options
author | 2021-08-29 12:59:04 -0700 | |
---|---|---|
committer | 2021-08-29 12:59:04 -0700 | |
commit | 1c22088640e5deeadd61017bd90920b652685b5f (patch) | |
tree | 59d110a7c8792c39e0c1ea180fa972eee1c4662d /src/ids.rs | |
parent | 8d5779a661f4537ef7d87a44bdfbf240eb054ff1 (diff) | |
download | notion-1c22088640e5deeadd61017bd90920b652685b5f.tar.gz notion-1c22088640e5deeadd61017bd90920b652685b5f.tar.zst notion-1c22088640e5deeadd61017bd90920b652685b5f.zip |
Notion API Version 2021-08-16 support; fix a bunch of modling errors as well
Diffstat (limited to 'src/ids.rs')
-rw-r--r-- | src/ids.rs | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/ids.rs b/src/ids.rs new file mode 100644 index 0000000..6febe63 --- /dev/null +++ b/src/ids.rs @@ -0,0 +1,52 @@ +use std::fmt::Display; + +pub trait Identifier: Display { + fn value(&self) -> &str; +} + +/// Meant to be a helpful trait allowing anything that can be +/// identified by the type specified in `ById`. +pub trait AsIdentifier<ById: Identifier> { + fn as_id(&self) -> &ById; +} + +impl<T> AsIdentifier<T> for T +where + T: Identifier, +{ + fn as_id(&self) -> &T { + &self + } +} + +macro_rules! identifer { + ($name:ident) => { + #[derive(serde::Serialize, serde::Deserialize, Debug, Eq, PartialEq, Hash, Clone)] + #[serde(transparent)] + pub struct $name(String); + + impl Identifier for $name { + fn value(&self) -> &str { + &self.0 + } + } + + impl std::fmt::Display for $name { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + self.0.fmt(f) + } + } + }; +} + +identifer!(DatabaseId); +identifer!(PageId); +identifer!(BlockId); +identifer!(UserId); +identifer!(PropertyId); + +impl From<PageId> for BlockId { + fn from(page_id: PageId) -> Self { + BlockId(page_id.0) + } +} |