mant_protocol/
selector.rs1use std::{borrow::Borrow, fmt, ops::Deref};
4
5use schemars::JsonSchema;
6use serde::{Deserialize, Serialize};
7
8#[derive(
10 Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema,
11)]
12#[serde(transparent)]
13pub struct NodePath(String);
14
15impl NodePath {
16 #[must_use]
18 pub fn new(value: impl Into<String>) -> Self {
19 Self(value.into())
20 }
21
22 #[must_use]
24 pub fn as_str(&self) -> &str {
25 &self.0
26 }
27
28 #[must_use]
30 pub fn into_string(self) -> String {
31 self.0
32 }
33}
34
35impl From<String> for NodePath {
36 fn from(value: String) -> Self {
37 Self(value)
38 }
39}
40
41impl From<&str> for NodePath {
42 fn from(value: &str) -> Self {
43 Self(value.to_owned())
44 }
45}
46
47impl AsRef<str> for NodePath {
48 fn as_ref(&self) -> &str {
49 self.as_str()
50 }
51}
52
53impl Borrow<str> for NodePath {
54 fn borrow(&self) -> &str {
55 self.as_str()
56 }
57}
58
59impl Deref for NodePath {
60 type Target = str;
61
62 fn deref(&self) -> &Self::Target {
63 self.as_str()
64 }
65}
66
67impl fmt::Display for NodePath {
68 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
69 formatter.write_str(self.as_str())
70 }
71}
72
73impl PartialEq<str> for NodePath {
74 fn eq(&self, other: &str) -> bool {
75 self.as_str() == other
76 }
77}
78
79impl PartialEq<&str> for NodePath {
80 fn eq(&self, other: &&str) -> bool {
81 self.as_str() == *other
82 }
83}