Skip to main content

opcua_server/session/
continuation_points.rs

1use std::any::Any;
2
3/// Representation of a dynamic continuation point.
4/// Each node manager may provide their own continuation point type,
5/// which is stored by the server. This wraps that value and provides interfaces
6/// to access it for a given node manager.
7pub struct ContinuationPoint {
8    payload: Box<dyn Any + Send + Sync + 'static>,
9}
10
11impl ContinuationPoint {
12    /// Create a new continuation point with `item` as content.
13    pub fn new<T: Send + Sync + 'static>(item: Box<T>) -> Self {
14        Self { payload: item }
15    }
16
17    /// Retrieve the value of the continuation point.
18    /// This will return `None` if the stored value is not equal to the
19    /// given type. Most node managers should report an error if this happens.
20    pub fn get<T: Send + Sync + 'static>(&self) -> Option<&T> {
21        self.payload.downcast_ref()
22    }
23
24    /// Retrieve the value of the continuation point.
25    /// This will return `None` if the stored value is not equal to the
26    /// given type. Most node managers should report an error if this happens.
27    pub fn get_mut<T: Send + Sync + 'static>(&mut self) -> Option<&mut T> {
28        self.payload.downcast_mut()
29    }
30
31    /// Consume this continuation point and return a specific type.
32    pub fn take<T: Send + Sync + 'static>(self) -> Option<Box<T>> {
33        self.payload.downcast().ok()
34    }
35}
36
37/// Continuation point implementation used when continuation is necessary, but
38/// the last called node manager is empty.
39pub(crate) struct EmptyContinuationPoint;