Skip to main content

Request

Struct Request 

Source
pub struct Request { /* private fields */ }
Expand description

Blocking analogue of core::Request. Every method mirrors the async one without the .await. The hidden current-thread runtime runs the await internally.

Request is !Sync because the Runtime it owns is; clone one via new per thread that needs independent blocking access, or use the async API if you need Sync.

Implementations§

Source§

impl Request

Source

pub fn new() -> Result<Self>

Create a new handle. Spawns the async driver thread and allocates a single-threaded tokio runtime to drive its futures to completion.

Source

pub fn connect_to(url: &str, opts: ConnectionOptions) -> Result<Self>

Construct + connect in one call.

use motorcortex_rust::{ConnectionOptions, blocking::Request};
let opts = ConnectionOptions::new("mcx.cert.crt".into(), 1000, 1000);
let req = Request::connect_to("wss://127.0.0.1:5568", opts)?;
req.request_parameter_tree()?;
let v: f64 = req.get_parameter("root/Control/dummyDouble")?;
println!("{v}");
Examples found in repository?
examples/blocking_request.rs (line 27)
15fn main() -> Result<()> {
16    let mut args = env::args().skip(1);
17    let url = args.next().unwrap_or_else(|| "wss://127.0.0.1:5568:5567".into());
18    let cert = args.next().unwrap_or_else(|| "tests/mcx.cert.crt".into());
19    let user = args.next().unwrap_or_else(|| "root".into());
20    let pass = args.next().unwrap_or_default();
21    let path = args
22        .next()
23        .unwrap_or_else(|| "root/Control/dummyDouble".into());
24
25    let (req_url, _sub_url) = parse_url(&url)?;
26    let opts = ConnectionOptions::new(cert, 5_000, 5_000);
27    let req = Request::connect_to(&req_url, opts)?;
28    req.login(&user, &pass)?;
29    req.request_parameter_tree()?;
30
31    let value: f64 = req.get_parameter(&path)?;
32    println!("{path} = {value}");
33
34    req.disconnect()?;
35    Ok(())
36}
Source

pub fn connect(&self, url: &str, opts: ConnectionOptions) -> Result<()>

Source

pub fn disconnect(&self) -> Result<()>

Examples found in repository?
examples/blocking_request.rs (line 34)
15fn main() -> Result<()> {
16    let mut args = env::args().skip(1);
17    let url = args.next().unwrap_or_else(|| "wss://127.0.0.1:5568:5567".into());
18    let cert = args.next().unwrap_or_else(|| "tests/mcx.cert.crt".into());
19    let user = args.next().unwrap_or_else(|| "root".into());
20    let pass = args.next().unwrap_or_default();
21    let path = args
22        .next()
23        .unwrap_or_else(|| "root/Control/dummyDouble".into());
24
25    let (req_url, _sub_url) = parse_url(&url)?;
26    let opts = ConnectionOptions::new(cert, 5_000, 5_000);
27    let req = Request::connect_to(&req_url, opts)?;
28    req.login(&user, &pass)?;
29    req.request_parameter_tree()?;
30
31    let value: f64 = req.get_parameter(&path)?;
32    println!("{path} = {value}");
33
34    req.disconnect()?;
35    Ok(())
36}
Source

pub fn login(&self, user: &str, pass: &str) -> Result<StatusCode>

Examples found in repository?
examples/blocking_request.rs (line 28)
15fn main() -> Result<()> {
16    let mut args = env::args().skip(1);
17    let url = args.next().unwrap_or_else(|| "wss://127.0.0.1:5568:5567".into());
18    let cert = args.next().unwrap_or_else(|| "tests/mcx.cert.crt".into());
19    let user = args.next().unwrap_or_else(|| "root".into());
20    let pass = args.next().unwrap_or_default();
21    let path = args
22        .next()
23        .unwrap_or_else(|| "root/Control/dummyDouble".into());
24
25    let (req_url, _sub_url) = parse_url(&url)?;
26    let opts = ConnectionOptions::new(cert, 5_000, 5_000);
27    let req = Request::connect_to(&req_url, opts)?;
28    req.login(&user, &pass)?;
29    req.request_parameter_tree()?;
30
31    let value: f64 = req.get_parameter(&path)?;
32    println!("{path} = {value}");
33
34    req.disconnect()?;
35    Ok(())
36}
Source

pub fn logout(&self) -> Result<StatusCode>

Source

pub fn request_parameter_tree(&self) -> Result<StatusCode>

Examples found in repository?
examples/blocking_request.rs (line 29)
15fn main() -> Result<()> {
16    let mut args = env::args().skip(1);
17    let url = args.next().unwrap_or_else(|| "wss://127.0.0.1:5568:5567".into());
18    let cert = args.next().unwrap_or_else(|| "tests/mcx.cert.crt".into());
19    let user = args.next().unwrap_or_else(|| "root".into());
20    let pass = args.next().unwrap_or_default();
21    let path = args
22        .next()
23        .unwrap_or_else(|| "root/Control/dummyDouble".into());
24
25    let (req_url, _sub_url) = parse_url(&url)?;
26    let opts = ConnectionOptions::new(cert, 5_000, 5_000);
27    let req = Request::connect_to(&req_url, opts)?;
28    req.login(&user, &pass)?;
29    req.request_parameter_tree()?;
30
31    let value: f64 = req.get_parameter(&path)?;
32    println!("{path} = {value}");
33
34    req.disconnect()?;
35    Ok(())
36}
Source

pub fn get_parameter_tree_hash(&self) -> Result<u32>

Source

pub fn get_parameter<V>(&self, path: &str) -> Result<V>

Examples found in repository?
examples/blocking_request.rs (line 31)
15fn main() -> Result<()> {
16    let mut args = env::args().skip(1);
17    let url = args.next().unwrap_or_else(|| "wss://127.0.0.1:5568:5567".into());
18    let cert = args.next().unwrap_or_else(|| "tests/mcx.cert.crt".into());
19    let user = args.next().unwrap_or_else(|| "root".into());
20    let pass = args.next().unwrap_or_default();
21    let path = args
22        .next()
23        .unwrap_or_else(|| "root/Control/dummyDouble".into());
24
25    let (req_url, _sub_url) = parse_url(&url)?;
26    let opts = ConnectionOptions::new(cert, 5_000, 5_000);
27    let req = Request::connect_to(&req_url, opts)?;
28    req.login(&user, &pass)?;
29    req.request_parameter_tree()?;
30
31    let value: f64 = req.get_parameter(&path)?;
32    println!("{path} = {value}");
33
34    req.disconnect()?;
35    Ok(())
36}
Source

pub fn set_parameter<V>(&self, path: &str, value: V) -> Result<StatusCode>

Source

pub fn get_parameters<T>(&self, paths: &[&str]) -> Result<T>
where T: GetParameterTuple,

Source

pub fn set_parameters<T>(&self, paths: &[&str], values: T) -> Result<StatusCode>
where T: SetParameterTuple,

Source

pub fn create_group<I>( &self, paths: I, alias: &str, fdiv: u32, ) -> Result<GroupStatusMsg>
where I: Parameters,

Source

pub fn remove_group(&self, alias: &str) -> Result<StatusCode>

Source

pub fn parameter_tree(&self) -> Arc<RwLock<ParameterTree>>

Shared parameter-tree cache. Populated by request_parameter_tree.

Source

pub fn as_async(&self) -> &Request

Access the inner async handle — useful when one part of your program is blocking and another is async.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.