opcua_nodes/import.rs
1use opcua_types::NodeId;
2
3use super::NodeType;
4
5pub use opcua_types::NodeSetNamespaceMapper;
6
7#[derive(Debug)]
8/// A reference produced by a type implementing [`NodeSetImport`].
9/// Note that the source of this reference is given by the node in the outer [`ImportedItem`]
10pub struct ImportedReference {
11 /// Reference target ID.
12 pub target_id: NodeId,
13 /// Reference type ID.
14 pub type_id: NodeId,
15 /// Whether this is a forward or inverse reference.
16 pub is_forward: bool,
17}
18
19#[derive(Debug)]
20/// A node with associated references produced by a type implementing [`NodeSetImport`]
21pub struct ImportedItem {
22 /// The imported node.
23 pub node: NodeType,
24 /// The list of imported references.
25 pub references: Vec<ImportedReference>,
26}
27
28/// Trait for a type that wraps a nodeset import.
29/// Currently this is implemeneted by the [`crate::xml::NodeSet2Import`] type
30/// with the `xml` feature, and by a type in the root of node set imports generated by
31/// `async-opcua-codegen`
32pub trait NodeSetImport {
33 /// Register all namespaces used by this importer in a node set map.
34 fn register_namespaces(&self, namespaces: &mut NodeSetNamespaceMapper);
35
36 /// Get a list of namespaces that this import _owns_. This must be a subset of the
37 /// namespaces it uses, registered in `register_namespaces`
38 fn get_own_namespaces(&self) -> Vec<String>;
39
40 /// Create an iterator over items imported from the nodeset.
41 /// This will usually be lazy.
42 fn load<'a>(
43 &'a self,
44 namespaces: &'a NodeSetNamespaceMapper,
45 ) -> Box<dyn Iterator<Item = ImportedItem> + 'a>;
46}