Struct opcua_client::prelude::ClientBuilder
source · [−]pub struct ClientBuilder { /* private fields */ }
Expand description
The ClientBuilder
is a builder for producing a Client
. It is an alternative to constructing
a ClientConfig
from file or from scratch.
Example
use opcua_client::prelude::*;
fn main() {
let builder = ClientBuilder::new()
.application_name("OPC UA Sample Client")
.application_uri("urn:SampleClient")
.pki_dir("./pki")
.endpoints(vec![
("sample_endpoint", ClientEndpoint {
url: String::from("opc.tcp://127.0.0.1:4855/"),
security_policy: String::from(SecurityPolicy::None.to_str()),
security_mode: String::from(MessageSecurityMode::None),
user_token_id: ANONYMOUS_USER_TOKEN_ID.to_string(),
}),
])
.default_endpoint("sample_endpoint")
.create_sample_keypair(true)
.trust_server_certs(true)
.user_token("sample_user", ClientUserToken::user_pass("sample1", "sample1pwd"));
let client = builder.client().unwrap();
}
Implementations
sourceimpl ClientBuilder
impl ClientBuilder
sourcepub fn new() -> ClientBuilder
pub fn new() -> ClientBuilder
Creates a ClientBuilder
sourcepub 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>,
Creates a ClientBuilder
using a configuration file as the initial state.
sourcepub fn client(self) -> Option<Client>
pub fn client(self) -> Option<Client>
Yields a Client
from the values set by the builder. If the builder is not in a valid state
it will return None
.
sourcepub fn config(self) -> ClientConfig
pub fn config(self) -> ClientConfig
Yields a ClientConfig
from the values set by the builder.
sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Tests if the builder is in a valid state to be able to yield a Client
.
sourcepub fn application_name<T>(self, application_name: T) -> Self where
T: Into<String>,
pub fn application_name<T>(self, application_name: T) -> Self where
T: Into<String>,
Sets the application name.
sourcepub fn application_uri<T>(self, application_uri: T) -> Self where
T: Into<String>,
pub fn application_uri<T>(self, application_uri: T) -> Self where
T: Into<String>,
Sets the application uri
sourcepub fn product_uri<T>(self, product_uri: T) -> Self where
T: Into<String>,
pub fn product_uri<T>(self, product_uri: T) -> Self where
T: Into<String>,
Sets the product uri.
sourcepub fn create_sample_keypair(self, create_sample_keypair: bool) -> Self
pub fn create_sample_keypair(self, create_sample_keypair: bool) -> Self
Sets whether the client should generate its own key pair if there is none found in the pki directory.
sourcepub fn certificate_path<T>(self, certificate_path: T) -> Self where
T: Into<PathBuf>,
pub fn certificate_path<T>(self, certificate_path: T) -> Self where
T: Into<PathBuf>,
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.
sourcepub fn private_key_path<T>(self, private_key_path: T) -> Self where
T: Into<PathBuf>,
pub fn private_key_path<T>(self, private_key_path: T) -> Self where
T: Into<PathBuf>,
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.
sourcepub fn trust_server_certs(self, trust_server_certs: bool) -> Self
pub fn trust_server_certs(self, trust_server_certs: bool) -> Self
Sets whether the client should automatically trust servers. If this is not set then
the client will reject the server upon first connect and the server’s certificate
must be manually moved from pki’s /rejected
folder to the /trusted
folder. If it is
set, then the server cert will automatically be stored in the /trusted
folder.
sourcepub fn verify_server_certs(self, verify_server_certs: bool) -> Self
pub fn verify_server_certs(self, verify_server_certs: bool) -> Self
Sets whether the client should verify server certificates. Regardless of this setting,
server certificates are always checked to see if they are trusted and have a valid key
length. In addition (if verify_server_certs
is unset or is set to true
) it will
verify the hostname, application uri and the not before / after values to ensure validity.
sourcepub fn pki_dir<T>(self, pki_dir: T) -> Self where
T: Into<PathBuf>,
pub fn pki_dir<T>(self, pki_dir: T) -> Self where
T: Into<PathBuf>,
Sets the pki directory where client’s own key pair is stored and where /trusted
and
/rejected
server certificates are stored.
sourcepub fn preferred_locales(self, preferred_locales: Vec<String>) -> Self
pub fn preferred_locales(self, preferred_locales: Vec<String>) -> Self
Sets the preferred locales of the client. These are passed to the server during session creation to ensure localized strings are in the preferred language.
sourcepub fn default_endpoint<T>(self, endpoint_id: T) -> Self where
T: Into<String>,
pub fn default_endpoint<T>(self, endpoint_id: T) -> Self where
T: Into<String>,
Sets the id of the default endpoint to connect to.
sourcepub fn endpoint<T>(self, endpoint_id: T, endpoint: ClientEndpoint) -> Self where
T: Into<String>,
pub fn endpoint<T>(self, endpoint_id: T, endpoint: ClientEndpoint) -> Self where
T: Into<String>,
Adds an endpoint to the list of endpoints the client knows of.
sourcepub fn endpoints<T>(self, endpoints: Vec<(T, ClientEndpoint)>) -> Self where
T: Into<String>,
pub fn endpoints<T>(self, endpoints: Vec<(T, ClientEndpoint)>) -> Self where
T: Into<String>,
Adds multiple endpoints to the list of endpoints the client knows of.
sourcepub fn user_token<T>(
self,
user_token_id: T,
user_token: ClientUserToken
) -> Self where
T: Into<String>,
pub fn user_token<T>(
self,
user_token_id: T,
user_token: ClientUserToken
) -> Self where
T: Into<String>,
Adds a user token to the list supported by the client.
sourcepub fn session_retry_limit(self, session_retry_limit: i32) -> Self
pub fn session_retry_limit(self, session_retry_limit: i32) -> Self
Sets the session retry limit.
sourcepub fn session_retry_interval(self, session_retry_interval: u32) -> Self
pub fn session_retry_interval(self, session_retry_interval: u32) -> Self
Sets the session retry interval.
sourcepub fn session_timeout(self, session_timeout: u32) -> Self
pub fn session_timeout(self, session_timeout: u32) -> Self
Sets the session timeout period.
sourcepub fn ignore_clock_skew(self) -> Self
pub fn ignore_clock_skew(self) -> Self
Sets whether the client should ignore clock skew so the client can make a successful connection to the server, even when the client and server clocks are out of sync.
sourcepub fn single_threaded_executor(self) -> Self
pub fn single_threaded_executor(self) -> Self
Configures the client to use a single-threaded executor. This reduces the number of threads used by the client.
sourcepub fn multi_threaded_executor(self) -> Self
pub fn multi_threaded_executor(self) -> Self
Configures the client to use a multi-threaded executor.
sourcepub fn session_name<T>(self, session_name: T) -> Self where
T: Into<String>,
pub fn session_name<T>(self, session_name: T) -> Self where
T: Into<String>,
Session name - the default name to use for a new session
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for ClientBuilder
impl Send for ClientBuilder
impl Sync for ClientBuilder
impl Unpin for ClientBuilder
impl UnwindSafe for ClientBuilder
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more