pub struct NodeId(/* private fields */);Expand description
A validated node identifier.
A NodeId may contain only [a-zA-Z0-9_.-], must be non-empty, and must
not start with . (dot-segments like . or .. could traverse into a
parent directory when the id is joined into a filesystem path). Unlike
DataId, a NodeId may not contain /, which separates
<node_id>/<output_id> in input-mapping syntax.
The exact id dora is additionally reserved: it names the built-in input
namespaces (dora/timer/..., dora/logs), which input-mapping parsing
matches before any user node, so a node called dora could never be
subscribed to. Only the exact string is reserved — dora-node, my-dora
and Dora all remain valid.
§Parsing vs. conversion (panic footgun)
Use str::parse / FromStr for untrusted input: it
returns Result<NodeId, InvalidId>. The From<String> conversion — and
therefore .into() and the auto-derived TryFrom<String> — panics on
an invalid id.
use dora_message::id::NodeId;
// Fallible path — always safe for untrusted input:
assert!("camera_node".parse::<NodeId>().is_ok());
assert!("node/out".parse::<NodeId>().is_err()); // '/' is not allowed in a NodeId
assert!("".parse::<NodeId>().is_err()); // empty is rejected
assert!(".hidden".parse::<NodeId>().is_err()); // leading '.' is rejected
assert!("dora".parse::<NodeId>().is_err()); // reserved for built-in inputs
assert!("dora-node".parse::<NodeId>().is_ok()); // only the exact id is reservedThe infallible-looking conversion panics on the same invalid input:
use dora_message::id::NodeId;
let _ = NodeId::from("node/out".to_string()); // panics — prefer .parse()Trait Implementations§
Source§impl<'de> Deserialize<'de> for NodeId
impl<'de> Deserialize<'de> for NodeId
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
impl Eq for NodeId
Source§impl From<String> for NodeId
§Panics
Panics if id is not a valid node id: if it is empty, contains
characters outside [a-zA-Z0-9_.-], starts with ., or is the
reserved id dora. Pre-validating against the character set alone is
not sufficient to make this conversion infallible.
impl From<String> for NodeId
§Panics
Panics if id is not a valid node id: if it is empty, contains
characters outside [a-zA-Z0-9_.-], starts with ., or is the
reserved id dora. Pre-validating against the character set alone is
not sufficient to make this conversion infallible.
For untrusted input, use id.parse::<NodeId>() which calls
FromStr::from_str and returns Result<Self, InvalidId>.
Do NOT use NodeId::try_from(s): TryFrom<String> is the
auto-derived blanket impl that delegates to this From impl, so it
panics exactly like .into(). Only parse::<NodeId>() / from_str
is fallible.
Source§impl JsonSchema for NodeId
impl JsonSchema for NodeId
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSource§impl Ord for NodeId
impl Ord for NodeId
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for NodeId
impl PartialOrd for NodeId
impl StructuralPartialEq for NodeId
Auto Trait Implementations§
impl Freeze for NodeId
impl RefUnwindSafe for NodeId
impl Send for NodeId
impl Sync for NodeId
impl Unpin for NodeId
impl UnsafeUnpin for NodeId
impl UnwindSafe for NodeId
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.