Skip to main content

NodeId

Struct NodeId 

Source
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

Source

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: &register,
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
Hide additional 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}
Source

pub fn namespace(&self) -> &str

The case-sensitive namespace URI, stable across sessions.

Source

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 Clone for NodeId

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NodeId

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for NodeId

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for NodeId

Source§

impl Hash for NodeId

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for NodeId

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for NodeId

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for NodeId

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for NodeId

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

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<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.