opcua_server/node_manager/build.rs
1use std::sync::Arc;
2
3use super::{DynNodeManager, NodeManager, ServerContext};
4
5/// Trait for node manager builders. Node managers are built at the same time as the server,
6/// after it has been configured, so each custom node manager needs to defined a builder type
7/// that implements this trait.
8///
9/// Build is infallible, if you need anything to fail, you need to either panic or
10/// propagate that failure to the user when creating the builder.
11pub trait NodeManagerBuilder {
12 /// Build the node manager, you can store data from `context`, but you should not
13 /// hold any locks when this method has finished.
14 fn build(self: Box<Self>, context: ServerContext) -> Arc<DynNodeManager>;
15}
16
17impl<T, R: NodeManager + Send + Sync + 'static> NodeManagerBuilder for T
18where
19 T: FnOnce(ServerContext) -> R,
20{
21 fn build(self: Box<Self>, context: ServerContext) -> Arc<DynNodeManager> {
22 Arc::new(self(context))
23 }
24}