pub struct Variable<T> { /* private fields */ }Expand description
Host-side handle to one scalar. Its Rust type fixes the OPC UA value type.
Implementations§
Source§impl<T: Into<Variant> + VariantType> Variable<T>
impl<T: Into<Variant> + VariantType> Variable<T>
Sourcepub fn set(&self, value: T) -> Result<(), ServerError>
pub fn set(&self, value: T) -> Result<(), ServerError>
Update the value and its source timestamp atomically.
Examples found in repository?
examples/local_server.rs (line 60)
15fn main() -> Result<(), Box<dyn Error>> {
16 let port = std::env::args()
17 .nth(1)
18 .unwrap_or_else(|| "4840".into())
19 .parse::<NonZeroU16>()?;
20 let args: Vec<String> = std::env::args().skip(2).collect();
21 let (host, runner) = match args.as_slice() {
22 [] => Server::loopback(port, "urn:example:line")?,
23 [uri, cert, key, client_uri, client_cert, policy @ ..] => Server::secure_with_policy(
24 SecureServerConfig {
25 bind: ([127, 0, 0, 1], port.get()).into(),
26 application_uri: uri,
27 certificate_der: &std::fs::read(cert)?,
28 private_key_der: &std::fs::read(key)?,
29 trusted_client_uri: client_uri,
30 trusted_client_certificate_der: &std::fs::read(client_cert)?,
31 },
32 "urn:example:line",
33 match policy {
34 [] => SecurityPolicy::Basic256Sha256,
35 [p] => [
36 SecurityPolicy::Basic256Sha256,
37 SecurityPolicy::Aes128Sha256RsaOaep,
38 SecurityPolicy::Aes256Sha256RsaPss,
39 ]
40 .into_iter()
41 .find(|policy| policy.uri().rsplit('#').next() == Some(p.as_str()))
42 .ok_or("unknown security policy")?,
43 _ => return Err("expected at most one security policy".into()),
44 },
45 )?,
46 _ => {
47 return Err(
48 "expected PORT [SERVER_URI SERVER.der SERVER_KEY.der CLIENT_URI CLIENT.der [POLICY]]".into(),
49 );
50 }
51 };
52 let counter = host.add_variable("PartsProduced", 0_u64)?;
53 let stop = Arc::new(AtomicBool::new(false));
54 let input_closed = Arc::clone(&stop);
55 thread::spawn(move || {
56 for line in io::stdin().lock().lines() {
57 let Ok(line) = line else { break };
58 match line.trim().parse() {
59 Ok(n) => {
60 if let Err(error) = counter.set(n) {
61 eprintln!("update failed: {error}");
62 }
63 }
64 Err(error) => eprintln!("expected a UInt64: {error}"),
65 }
66 }
67 input_closed.store(true, Ordering::Release);
68 });
69 eprintln!("Serving PartsProduced on opc.tcp://127.0.0.1:{port} while stdin is open");
70 runner.run_until(|| stop.load(Ordering::Acquire))?;
71 Ok(())
72}Auto Trait Implementations§
impl<T> Forget for Variable<T>
impl<T> Freeze for Variable<T>
impl<T> Move for Variable<T>
impl<T> RefUnwindSafe for Variable<T>
impl<T> Send for Variable<T>
impl<T> Sync for Variable<T>
impl<T> Unpin for Variable<T>
impl<T> UnsafeUnpin for Variable<T>
impl<T> UnwindSafe for Variable<T>
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more