pub struct NodeId { /* private fields */ }Expand description
A namespace URI and a typed OPC UA identifier. Namespace indexes are session-local.
Numeric identifiers use decimal, GUIDs use hyphenated hex, and opaque identifiers use RFC 4648 standard Base64. String identifier contents are case-sensitive.
Implementations§
Source§impl NodeId
impl NodeId
Sourcepub fn new(
namespace: impl Into<String>,
id: impl Into<String>,
) -> Result<Self, NodeIdError>
pub fn new( namespace: impl Into<String>, id: impl Into<String>, ) -> Result<Self, NodeIdError>
Create a canonical node identity from a namespace URI and a typed OPC UA identifier.
For example, NodeId::new("urn:plant:line-1", "i=00042") stores i=42.
Examples found in repository?
examples/project_meter.rs (line 17)
13fn main() -> Result<(), Box<dyn Error>> {
14 let contract = parse_contract(include_bytes!("../fixtures/meter/contract.json"))?;
15
16 // The independent close feed supplies the meter identity and the UTC quarter starts.
17 let register = NodeId::new("urn:example:meter", "s=GridImportWh")?;
18 let start = OffsetDateTime::parse("2026-10-25T00:45:00Z", &Rfc3339)?;
19 let window = MeterWindow {
20 device: "example-grid-incomer",
21 application_uri: "urn:example:grid-meter",
22 node: ®ister,
23 start,
24 end: start + Duration::minutes(30),
25 tolerance_wh: 1,
26 };
27 let mut projector = MeterProjector::new(&contract, window)?;
28
29 // In a live driver, push the MeterReading returned by client.read_meter(&contract).
30 for line in include_str!("../fixtures/meter/readings.ndjson").lines() {
31 let reading = parse_meter_reading(&contract, line.as_bytes())?;
32 projector.push(&reading)?;
33 }
34
35 let closes = [(start, 285_000), (start + Duration::minutes(15), 274_999)];
36 let result = projector.finish(&closes)?;
37 let mut output = io::stdout().lock();
38 serde_json::to_writer(&mut output, &result.trace)?;
39 writeln!(output)?;
40 Ok(())
41}More examples
examples/read.rs (line 31)
7fn main() -> Result<(), Box<dyn Error>> {
8 let args: Vec<_> = env::args().skip(1).collect();
9 if matches!(args.as_slice(), [arg] if arg == "-h" || arg == "--help") {
10 println!("Read UInt64 variables from an OPC UA server.\n\nUsage: {USAGE}");
11 return Ok(());
12 }
13 let [
14 endpoint,
15 server_uri,
16 server_cert,
17 client_uri,
18 client_cert,
19 key,
20 namespace,
21 ids @ ..,
22 ] = args.as_slice()
23 else {
24 return Err(format!("usage: {USAGE}").into());
25 };
26 if ids.is_empty() || ids.len() > opcua_kit::MAX_READ_NODES {
27 return Err("supply 1 to 1024 node identifiers".into());
28 }
29 let nodes = ids
30 .iter()
31 .map(|id| NodeId::new(namespace, id))
32 .collect::<Result<Vec<_>, _>>()?;
33 let client = Client::connect(ConnectionConfig {
34 endpoint,
35 server_application_uri: server_uri,
36 server_certificate_der: &fs::read(server_cert)?,
37 client_application_uri: client_uri,
38 client_certificate_der: &fs::read(client_cert)?,
39 client_private_key_der: &fs::read(key)?,
40 timeout: Duration::from_secs(5),
41 })?;
42 tokio::runtime::Builder::new_current_thread()
43 .enable_all()
44 .build()?
45 .block_on(async {
46 let result = client.read_scalars::<u64>(&nodes).await;
47 client.disconnect().await;
48 let mut unavailable = 0;
49 for (node, item) in nodes.iter().zip(result?) {
50 let id = node.identifier().escape_debug();
51 match item {
52 Ok(opcua_kit::Sample {
53 status: 0,
54 value: Some(value),
55 ..
56 }) => println!("{id} {value}"),
57 Ok(sample) => {
58 eprintln!("{id} unavailable (0x{:08X})", sample.status);
59 unavailable += 1;
60 }
61 Err(error) => {
62 eprintln!("{id} {error}");
63 unavailable += 1;
64 }
65 }
66 }
67 if unavailable != 0 {
68 return Err(format!("{unavailable} variable(s) unavailable").into());
69 }
70 Ok(())
71 })
72}Sourcepub fn identifier(&self) -> &str
pub fn identifier(&self) -> &str
The canonical identifier, including its OPC UA type prefix.
Examples found in repository?
examples/read.rs (line 50)
7fn main() -> Result<(), Box<dyn Error>> {
8 let args: Vec<_> = env::args().skip(1).collect();
9 if matches!(args.as_slice(), [arg] if arg == "-h" || arg == "--help") {
10 println!("Read UInt64 variables from an OPC UA server.\n\nUsage: {USAGE}");
11 return Ok(());
12 }
13 let [
14 endpoint,
15 server_uri,
16 server_cert,
17 client_uri,
18 client_cert,
19 key,
20 namespace,
21 ids @ ..,
22 ] = args.as_slice()
23 else {
24 return Err(format!("usage: {USAGE}").into());
25 };
26 if ids.is_empty() || ids.len() > opcua_kit::MAX_READ_NODES {
27 return Err("supply 1 to 1024 node identifiers".into());
28 }
29 let nodes = ids
30 .iter()
31 .map(|id| NodeId::new(namespace, id))
32 .collect::<Result<Vec<_>, _>>()?;
33 let client = Client::connect(ConnectionConfig {
34 endpoint,
35 server_application_uri: server_uri,
36 server_certificate_der: &fs::read(server_cert)?,
37 client_application_uri: client_uri,
38 client_certificate_der: &fs::read(client_cert)?,
39 client_private_key_der: &fs::read(key)?,
40 timeout: Duration::from_secs(5),
41 })?;
42 tokio::runtime::Builder::new_current_thread()
43 .enable_all()
44 .build()?
45 .block_on(async {
46 let result = client.read_scalars::<u64>(&nodes).await;
47 client.disconnect().await;
48 let mut unavailable = 0;
49 for (node, item) in nodes.iter().zip(result?) {
50 let id = node.identifier().escape_debug();
51 match item {
52 Ok(opcua_kit::Sample {
53 status: 0,
54 value: Some(value),
55 ..
56 }) => println!("{id} {value}"),
57 Ok(sample) => {
58 eprintln!("{id} unavailable (0x{:08X})", sample.status);
59 unavailable += 1;
60 }
61 Err(error) => {
62 eprintln!("{id} {error}");
63 unavailable += 1;
64 }
65 }
66 }
67 if unavailable != 0 {
68 return Err(format!("{unavailable} variable(s) unavailable").into());
69 }
70 Ok(())
71 })
72}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>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for NodeId
Source§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,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl PartialOrd for NodeId
impl PartialOrd for NodeId
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 NodeId
impl Sync for NodeId
impl Unpin for NodeId
impl UnsafeUnpin for NodeId
impl UnwindSafe for NodeId
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Mutably borrows from an owned value. Read more