diff options
author | metamuffin <metamuffin@disroot.org> | 2025-02-07 16:10:29 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-02-07 16:10:29 +0100 |
commit | 314bca18a43e22368a87fcad53d91190fe101b60 (patch) | |
tree | 3cf89e2a6904c5a6abae8fe92a5a3aa96501a63c /common | |
parent | 346095d20e3d817d150cbea49e87a49fbcaa2304 (diff) | |
download | jellything-314bca18a43e22368a87fcad53d91190fe101b60.tar jellything-314bca18a43e22368a87fcad53d91190fe101b60.tar.bz2 jellything-314bca18a43e22368a87fcad53d91190fe101b60.tar.zst |
nodes modified since endpoint
Diffstat (limited to 'common')
-rw-r--r-- | common/src/impl.rs | 15 | ||||
-rw-r--r-- | common/src/lib.rs | 4 |
2 files changed, 16 insertions, 3 deletions
diff --git a/common/src/impl.rs b/common/src/impl.rs index db702d3..1aeac22 100644 --- a/common/src/impl.rs +++ b/common/src/impl.rs @@ -8,6 +8,7 @@ use crate::{ TraktKind, }; use hex::FromHexError; +use serde::{Deserialize, Serialize}; use std::{fmt::Display, str::FromStr}; impl SourceTrackKind { @@ -242,3 +243,17 @@ impl From<String> for NodeIDOrSlug { Self::Slug(value) } } +impl Serialize for NodeID { + fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> { + serializer.serialize_str(&hex::encode(self.0)) + } +} +impl<'de> Deserialize<'de> for NodeID { + fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> { + let mut k = [0; 32]; + hex::decode_to_slice(String::deserialize(deserializer)?, &mut k).map_err(|_| { + <D::Error as serde::de::Error>::custom(format_args!("nodeid hex invalid")) + })?; + Ok(NodeID(k)) + } +} diff --git a/common/src/lib.rs b/common/src/lib.rs index 43adfba..3f9cfc3 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -22,9 +22,7 @@ use std::{ path::PathBuf, }; -#[derive( - Clone, Copy, Debug, Serialize, Deserialize, Encode, Decode, PartialEq, Eq, PartialOrd, Ord, -)] +#[derive(Clone, Copy, Debug, Encode, Decode, PartialEq, Eq, PartialOrd, Ord)] pub struct NodeID(pub [u8; 32]); pub enum NodeIDOrSlug { |