Skip to main content

Request

Struct Request 

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

Represents a request client that manages socket-based connections and interacts with the server.

§Thread Safety

Request is Send but not Sync. This means you can move a Request to another thread, but you cannot share it between threads by reference. The Req/Rep protocol requires strict send→receive ordering, which cannot be guaranteed with concurrent callers.

Each thread that needs concurrent server access should create its own Request instance, or protect shared access with a Mutex<Request>.

Implementations§

Source§

impl Request

Source

pub fn new() -> Self

Creates a new Request instance.

No socket is opened until connect() is called.

Source

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

Establishes a connection to a specified server URL using the given configuration options.

Opens a REQ socket and connects to the server.

§Arguments:
  • url - The server’s address (e.g., “wss://127.0.0.1:5568”).
  • connection_options - The connection settings, including TLS certificate and timeouts.
§Errors:

Returns MotorcortexError::Connection if the socket cannot be opened or the connection fails.

Source

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

Disconnects the current connection and frees the associated resources.

§Errors:

Returns MotorcortexError::Connection if the disconnection fails.

Source

pub fn login(&self, username: String, password: String) -> Result<StatusCode>

Sends a login message to the server with the specified username and password.

§Arguments:
  • username - The username to authenticate with.
  • password - The password for authentication.
§Returns:
  • Ok(StatusCode) - The status code representing the login response.
§Errors:

Returns MotorcortexError::Encode, MotorcortexError::Io, or MotorcortexError::Decode.

Source

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

Sends a logout message to the server.

§Returns:
  • Ok(StatusCode) - The status code representing the logout response.
§Errors:

Returns MotorcortexError::Encode, MotorcortexError::Io, or MotorcortexError::Decode.

Source

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

Requests and updates the client’s parameter tree from the server.

§Returns:
  • Ok(StatusCode) - The status code indicating the result of the request.
§Errors:

Returns MotorcortexError::Encode, MotorcortexError::Io, or MotorcortexError::Decode.

Source

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

Updates a specific parameter on the server with the provided value.

§Arguments:
  • path - The hierarchical path to the parameter being updated.
  • value - The new value for the parameter. Must implement SetParameterValue.
§Returns:
  • Ok(StatusCode) - The status code after setting the parameter.
§Errors:

Returns MotorcortexError::ParameterNotFound if the path doesn’t exist in the tree. Returns MotorcortexError::Encode, MotorcortexError::Io, or MotorcortexError::Decode for communication failures.

Source

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

Sets multiple parameters on the server in a single request.

§Arguments:
  • paths - A vector of hierarchical paths to the parameters.
  • values - A tuple of values matching the paths.
§Errors:

Returns MotorcortexError::ParameterNotFound if any path doesn’t exist in the tree.

Source

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

Retrieves the value of a parameter from the server for the given path.

§Arguments:
  • path - The hierarchical path of the parameter to retrieve.
§Type Parameters:
  • V - The expected value type. The server value is automatically converted.
§Errors:

Returns MotorcortexError::ParameterNotFound if the path doesn’t exist in the tree. Returns MotorcortexError::Encode, MotorcortexError::Io, or MotorcortexError::Decode for communication failures.

Source

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

Retrieves multiple parameters from the server in a single request.

§Arguments:
  • paths - A vector of hierarchical paths.
§Type Parameters:
  • T - A tuple type matching the expected parameter types.
§Errors:

Returns MotorcortexError::Decode if the response cannot be decoded.

Source

pub fn get_parameter_tree(&self) -> Result<(StatusCode, ParameterTree)>

Retrieves the server’s parameter tree.

§Returns:
  • Ok((StatusCode, ParameterTree)) - The status code and the retrieved parameter tree.
§Errors:

Returns MotorcortexError::Decode if the tree message is invalid.

Source

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

Retrieves the hash of the server’s parameter tree for change detection.

Source

pub fn create_group<I>( &self, parameters: I, group_name: &str, frequency_divider: u32, ) -> Result<GroupStatusMsg>
where I: Parameters,

Creates a subscription group on the server.

§Arguments:
  • parameters - The parameter paths to include in the group.
  • group_name - An alias for the group.
  • frequency_divider - Update rate divider relative to the server’s base frequency.
Source

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

Removes a subscription group from the server.

§Arguments:
  • group_name - The alias of the group to remove.
Source

pub fn decode_message<T: Message + Default + Hash>( reply_slice: &[u8], ) -> Result<T>

Decodes a byte slice into a specific Protobuf message type.

Trait Implementations§

Source§

impl Connection for Request

Implement the common trait for Request

Source§

fn connect(&mut self, url: &str, options: ConnectionOptions) -> Result<()>

Connect to a server
Source§

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

Disconnect from the server

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.