use std::fmt::Debug;
use open62541_sys::UA_DataType;
use crate::{DataType, Result, ua};
pub trait DataTypeExt: Debug + Clone {
type Inner: DataType;
fn from_inner(value: Self::Inner) -> Result<Self>;
fn into_inner(self) -> Self::Inner;
}
impl<T: DataType> DataTypeExt for T {
type Inner = Self;
fn from_inner(value: Self::Inner) -> Result<Self> {
Ok(value)
}
fn into_inner(self) -> Self::Inner {
self
}
}
pub trait Attribute: Debug + Copy {
type Value: DataTypeExt + Send;
fn id(&self) -> ua::AttributeId;
}
pub trait Attributes: DataType {
fn node_class(&self) -> ua::NodeClass;
fn attribute_type(&self) -> *const UA_DataType;
#[must_use]
fn with_display_name(self, display_name: &ua::LocalizedText) -> Self;
fn as_node_attributes(&self) -> &ua::NodeAttributes;
}
pub trait CustomCertificateVerification {
fn verify_certificate(&self, certificate: &ua::ByteString) -> ua::StatusCode;
fn verify_application_uri(
&self,
certificate: &ua::ByteString,
application_uri: &ua::String,
) -> ua::StatusCode;
}
#[cfg(feature = "mbedtls")]
pub trait PrivateKeyPasswordCallback {
fn private_key_password(&self) -> Result<crate::Password>;
}
#[cfg(feature = "mbedtls")]
impl<F> PrivateKeyPasswordCallback for F
where
F: Fn() -> Result<crate::Password>,
{
fn private_key_password(&self) -> Result<crate::Password> {
self()
}
}
pub trait MonitoringFilter: Debug + Send + Sync + 'static {
fn to_extension_object(&self) -> ua::ExtensionObject;
}
impl MonitoringFilter for Box<dyn MonitoringFilter> {
fn to_extension_object(&self) -> ua::ExtensionObject {
(**self).to_extension_object()
}
}
pub trait FilterOperand: Debug + Send + Sync + 'static {
fn to_extension_object(&self) -> ua::ExtensionObject;
}
impl FilterOperand for Box<dyn FilterOperand> {
fn to_extension_object(&self) -> ua::ExtensionObject {
(**self).to_extension_object()
}
}