Skip to content

Commit

Permalink
cargo fmt files
Browse files Browse the repository at this point in the history
  • Loading branch information
locka99 committed Nov 22, 2020
1 parent 154995c commit b56e407
Show file tree
Hide file tree
Showing 178 changed files with 18,548 additions and 7,287 deletions.
66 changes: 51 additions & 15 deletions client/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub struct ClientBuilder {
impl Default for ClientBuilder {
fn default() -> Self {
ClientBuilder {
config: ClientConfig::default()
config: ClientConfig::default(),
}
}
}
Expand All @@ -59,9 +59,12 @@ impl ClientBuilder {
}

/// Creates a `ClientBuilder` using a configuration file as the initial state.
pub fn from_config<T>(path: T) -> Result<ClientBuilder, ()> where T: Into<PathBuf> {
pub fn from_config<T>(path: T) -> Result<ClientBuilder, ()>
where
T: Into<PathBuf>,
{
Ok(ClientBuilder {
config: ClientConfig::load(&path.into())?
config: ClientConfig::load(&path.into())?,
})
}

Expand Down Expand Up @@ -90,19 +93,28 @@ impl ClientBuilder {
}

/// Sets the application name.
pub fn application_name<T>(mut self, application_name: T) -> Self where T: Into<String> {
pub fn application_name<T>(mut self, application_name: T) -> Self
where
T: Into<String>,
{
self.config.application_name = application_name.into();
self
}

/// Sets the application uri
pub fn application_uri<T>(mut self, application_uri: T) -> Self where T: Into<String> {
pub fn application_uri<T>(mut self, application_uri: T) -> Self
where
T: Into<String>,
{
self.config.application_uri = application_uri.into();
self
}

/// Sets the product uri.
pub fn product_uri<T>(mut self, product_uri: T) -> Self where T: Into<String> {
pub fn product_uri<T>(mut self, product_uri: T) -> Self
where
T: Into<String>,
{
self.config.product_uri = product_uri.into();
self
}
Expand All @@ -117,15 +129,21 @@ impl ClientBuilder {
/// Sets a custom client certificate path. The path is required to be provided as a partial
/// path relative to the PKI directory. If set, this path will be used to read the client
/// certificate from disk. The certificate can be in either the .der or .pem format.
pub fn certificate_path<T>(mut self, certificate_path: T) -> Self where T: Into<PathBuf> {
pub fn certificate_path<T>(mut self, certificate_path: T) -> Self
where
T: Into<PathBuf>,
{
self.config.certificate_path = Some(certificate_path.into());
self
}

/// Sets a custom private key path. The path is required to be provided as a partial path
/// relative to the PKI directory. If set, this path will be used to read the private key
/// from disk.
pub fn private_key_path<T>(mut self, private_key_path: T) -> Self where T: Into<PathBuf> {
pub fn private_key_path<T>(mut self, private_key_path: T) -> Self
where
T: Into<PathBuf>,
{
self.config.private_key_path = Some(private_key_path.into());
self
}
Expand All @@ -141,7 +159,10 @@ impl ClientBuilder {

/// Sets the pki directory where client's own key pair is stored and where `/trusted` and
/// `/rejected` server certificates are stored.
pub fn pki_dir<T>(mut self, pki_dir: T) -> Self where T: Into<PathBuf> {
pub fn pki_dir<T>(mut self, pki_dir: T) -> Self
where
T: Into<PathBuf>,
{
self.config.pki_dir = pki_dir.into();
self
}
Expand All @@ -154,27 +175,39 @@ impl ClientBuilder {
}

/// Sets the id of the default endpoint to connect to.
pub fn default_endpoint<T>(mut self, endpoint_id: T) -> Self where T: Into<String> {
pub fn default_endpoint<T>(mut self, endpoint_id: T) -> Self
where
T: Into<String>,
{
self.config.default_endpoint = endpoint_id.into();
self
}

/// Adds an endpoint to the list of endpoints the client knows of.
pub fn endpoint<T>(mut self, endpoint_id: T, endpoint: ClientEndpoint) -> Self where T: Into<String> {
pub fn endpoint<T>(mut self, endpoint_id: T, endpoint: ClientEndpoint) -> Self
where
T: Into<String>,
{
self.config.endpoints.insert(endpoint_id.into(), endpoint);
self
}

/// Adds multiple endpoints to the list of endpoints the client knows of.
pub fn endpoints<T>(mut self, endpoints: Vec<(T, ClientEndpoint)>) -> Self where T: Into<String> {
pub fn endpoints<T>(mut self, endpoints: Vec<(T, ClientEndpoint)>) -> Self
where
T: Into<String>,
{
for e in endpoints {
self.config.endpoints.insert(e.0.into(), e.1);
};
}
self
}

/// Adds a user token to the list supported by the client.
pub fn user_token<T>(mut self, user_token_id: T, user_token: ClientUserToken) -> Self where T: Into<String> {
pub fn user_token<T>(mut self, user_token_id: T, user_token: ClientUserToken) -> Self
where
T: Into<String>,
{
let user_token_id = user_token_id.into();
if user_token_id == ANONYMOUS_USER_TOKEN_ID {
panic!("User token id {} is reserved", user_token_id);
Expand Down Expand Up @@ -237,7 +270,10 @@ fn client_builder() {
assert_eq!(c.private_key_path, Some(PathBuf::from("keyxyz")));
assert_eq!(c.trust_server_certs, true);
assert_eq!(c.pki_dir, PathBuf::from_str("pkixyz").unwrap());
assert_eq!(c.preferred_locales, vec!["a".to_string(), "b".to_string(), "c".to_string()]);
assert_eq!(
c.preferred_locales,
vec!["a".to_string(), "b".to_string(), "c".to_string()]
);
assert_eq!(c.default_endpoint, "http://default");
assert_eq!(c.session_retry_interval, 1234);
assert_eq!(c.session_retry_limit, 999);
Expand Down
47 changes: 23 additions & 24 deletions client/src/callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@
//! [`DataChangeCallback`]: ./struct.DataChangeCallback.html
//! [`EventCallback`]: ./struct.EventCallback.html

use std::fmt;

use opcua_types::{
service_types::EventNotificationList,
status_code::StatusCode,
};
use opcua_types::{service_types::EventNotificationList, status_code::StatusCode};

use crate::subscription::MonitoredItem;

Expand Down Expand Up @@ -51,7 +47,6 @@ pub trait OnConnectionStatusChange {
fn on_connection_status_change(&mut self, connected: bool);
}


/// The `OnSessionClosed` trait can be used to register on a session and called to notify the client
/// that the session has closed.
pub trait OnSessionClosed {
Expand All @@ -69,7 +64,7 @@ pub trait OnSessionClosed {
/// a data change occurs.
pub struct DataChangeCallback {
/// The actual call back
cb: Box<dyn Fn(Vec<&MonitoredItem>) + Send + Sync + 'static>
cb: Box<dyn Fn(Vec<&MonitoredItem>) + Send + Sync + 'static>,
}

impl OnSubscriptionNotification for DataChangeCallback {
Expand All @@ -80,18 +75,19 @@ impl OnSubscriptionNotification for DataChangeCallback {

impl DataChangeCallback {
/// Constructs a callback from the supplied function
pub fn new<CB>(cb: CB) -> Self where CB: Fn(Vec<&MonitoredItem>) + Send + Sync + 'static {
Self {
cb: Box::new(cb)
}
pub fn new<CB>(cb: CB) -> Self
where
CB: Fn(Vec<&MonitoredItem>) + Send + Sync + 'static,
{
Self { cb: Box::new(cb) }
}
}

/// This is a concrete implementation of [`OnSubscriptionNotification`] that calls a function
/// when an event occurs.
pub struct EventCallback {
/// The actual call back
cb: Box<dyn Fn(&EventNotificationList) + Send + Sync + 'static>
cb: Box<dyn Fn(&EventNotificationList) + Send + Sync + 'static>,
}

impl OnSubscriptionNotification for EventCallback {
Expand All @@ -102,10 +98,11 @@ impl OnSubscriptionNotification for EventCallback {

impl EventCallback {
/// Constructs a callback from the supplied function
pub fn new<CB>(cb: CB) -> Self where CB: Fn(&EventNotificationList) + Send + Sync + 'static {
Self {
cb: Box::new(cb)
}
pub fn new<CB>(cb: CB) -> Self
where
CB: Fn(&EventNotificationList) + Send + Sync + 'static,
{
Self { cb: Box::new(cb) }
}
}

Expand Down Expand Up @@ -133,10 +130,11 @@ impl OnConnectionStatusChange for ConnectionStatusCallback {

impl ConnectionStatusCallback {
// Constructor
pub fn new<CB>(cb: CB) -> Self where CB: FnMut(bool) + Send + Sync + 'static {
Self {
cb: Box::new(cb)
}
pub fn new<CB>(cb: CB) -> Self
where
CB: FnMut(bool) + Send + Sync + 'static,
{
Self { cb: Box::new(cb) }
}
}

Expand All @@ -154,9 +152,10 @@ impl OnSessionClosed for SessionClosedCallback {

impl SessionClosedCallback {
// Constructor
pub fn new<CB>(cb: CB) -> Self where CB: FnMut(StatusCode) + Send + Sync + 'static {
Self {
cb: Box::new(cb)
}
pub fn new<CB>(cb: CB) -> Self
where
CB: FnMut(StatusCode) + Send + Sync + 'static,
{
Self { cb: Box::new(cb) }
}
}
Loading

0 comments on commit b56e407

Please sign in to comment.