twizzler_driver/request/
submit.rs

1#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
2/// Error that can arise from submitting a set of requests.
3pub enum SubmitError<E> {
4    /// Error from the driver.
5    DriverError(E),
6    /// The request engine is shutdown.
7    IsShutdown,
8}
9// TODO: impl Error
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
12/// A wrapper around a request that adds an ID alongside a request. The ID is automatically
13/// allocated internally by the request manager after the [SubmitRequest] is submitted.
14pub struct SubmitRequest<T> {
15    id: u64,
16    data: T,
17}
18
19impl<T> SubmitRequest<T> {
20    /// Construct a new [SubmitRequest].
21    pub fn new(data: T) -> Self {
22        Self { id: 0, data }
23    }
24
25    /// Get a reference to the data.
26    pub fn data(&self) -> &T {
27        &self.data
28    }
29
30    /// Get a mutable reference to the data.
31    pub fn data_mut(&mut self) -> &mut T {
32        &mut self.data
33    }
34    /// Get the ID of the request. Note that this number is only meaningful after the request has
35    /// been submitted.
36    pub fn id(&self) -> u64 {
37        self.id
38    }
39
40    pub(crate) fn set_id(&mut self, id: u64) {
41        self.id = id;
42    }
43}