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<NodeId, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<NodeId, <D as Deserializer<'de>>::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
Source§impl Serialize for NodeId
impl Serialize for NodeId
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for NodeId
Auto Trait Implementations§
impl Forget for NodeId
impl Freeze for NodeId
impl Move for NodeId
impl RefUnwindSafe for NodeId
impl Send for NodeIdwhere
RawVecInner: Send,
impl Sync for NodeIdwhere
RawVecInner: Sync,
impl Unpin for NodeId
impl UnsafeUnpin for NodeId
impl UnwindSafe for NodeIdwhere
RawVecInner: UnwindSafe,
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.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more