nodecraft/id/
impls.rs

1#[cfg(any(feature = "std", feature = "alloc"))]
2mod id;
3#[cfg(any(feature = "std", feature = "alloc"))]
4pub use id::*;
5
6mod id_ref;
7pub use id_ref::*;
8
9/// Errors that can occur when transforming an [`NodeId`].
10#[derive(Debug, thiserror::Error)]
11pub enum ParseNodeIdError {
12  /// Returned when the id is empty.
13  #[error("id cannot be empty")]
14  Empty,
15  /// Returned when the id is too large.
16  #[error("id is too large, maximum size is {maximum} bytes, but got {actual} bytes")]
17  TooLarge {
18    /// The maximum size of the [`NodeId`].
19    maximum: usize,
20    /// The actual size of the [`NodeId`].
21    actual: usize,
22  },
23  /// Returned when the buffer is too small to encode the [`NodeId`].
24  #[error("insufficient buffer, required: {required}, remaining: {remaining}")]
25  InsufficientBuffer {
26    /// The buffer size required to encode the [`NodeId`].
27    required: u64,
28    /// The buffer size remaining.
29    remaining: u64,
30  },
31  /// Returned when the id is not a valid utf8 string.
32  #[error(transparent)]
33  Utf8Error(#[from] core::str::Utf8Error),
34}
35
36impl ParseNodeIdError {
37  #[inline]
38  const fn too_large(maximum: usize, actual: usize) -> Self {
39    Self::TooLarge { maximum, actual }
40  }
41}