Skip to main content

ResponseSlot

Struct ResponseSlot 

Source
pub struct ResponseSlot(pub Mutex<RefCell<Response>>, pub Notify, _);
Expand description

The response slot for each UDS request This struct holds the response data and a notification object to signal when the response is ready

Tuple Fields§

§0: Mutex<RefCell<Response>>§1: Notify

Implementations§

Source§

impl ResponseSlot

Source

pub fn new(timeout_ms: Option<u64>) -> Self

Create a new ResponseSlot.

This will initialize the slot with a default error (NotSupported) and set up the notification system. The timeout_ms is an optional input in milisecs, the default timeout is 1000ms.

Source

pub async fn get(&self) -> Result<Response, DiagError>

Get a response in a blocking manner. This will block forever until a response is available.

It waits for the notification to be triggered and then locks the Mutex to retrieve the response.

Source

pub async fn wait_for_response(&self) -> Response

Get a response with a timeout. If no response is received within the timeout period, an error is returned.

This function uses tokio::select! to wait for either the notification or the timeout. If the timeout expires, it returns a Timeout error.

Source

pub async fn update_response(&self, new_data: Vec<u8>)

Update the response data in the response slot and notify the waiting task.

This function is used to update the response after receiving new data. It creates a UdsFrame from the provided new_data and replaces the current response data. After updating, it notifies the waiting task that the response is ready.

Trait Implementations§

Source§

impl Default for ResponseSlot

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.