Skip to content

Commit

Permalink
feat(common): Conversion from NonZeroU64 to NodeId (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwcampbell authored Jul 19, 2022
1 parent 4d27234 commit b7adfb9
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ use schemars_lib::JsonSchema;
use serde_lib as serde;
#[cfg(feature = "serde")]
use serde_lib::{Deserialize, Serialize};
use std::ops::Range;
use std::{
num::{NonZeroU128, NonZeroU64},
ops::Range,
};

/// The type of an accessibility node.
///
Expand Down Expand Up @@ -580,7 +583,7 @@ pub enum StringEncoding {

// This is NonZeroU128 because we regularly store Option<NodeId>.
// 128-bit to handle UUIDs.
pub type NodeIdContent = std::num::NonZeroU128;
pub type NodeIdContent = NonZeroU128;

/// The stable identity of a [`Node`], unique within the node's tree.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
Expand All @@ -589,6 +592,12 @@ pub type NodeIdContent = std::num::NonZeroU128;
#[cfg_attr(feature = "serde", serde(crate = "serde"))]
pub struct NodeId(pub NodeIdContent);

impl From<NonZeroU64> for NodeId {
fn from(inner: NonZeroU64) -> Self {
Self(inner.into())
}
}

/// The globally unique ID of a [`Tree`].
///
/// The format of this ID is up to the implementer. A [v4 UUID] is a safe choice.
Expand Down

0 comments on commit b7adfb9

Please sign in to comment.