Skip to main content

wireshift_core/ops/
nop.rs

1//! Implementation of a No-Op operation over the Ring instance.
2use crate::error::Result;
3use crate::op::{CompletionPayload, Op, OpDescriptor};
4
5/// A no-op request useful for smoke tests and synchronization.
6///
7/// ```no_run
8/// use wireshift::{Ring, RingConfig, ops::Nop};
9///
10/// let ring = Ring::new(RingConfig::default())?;
11/// ring.submit(Nop)?.wait(None)?;
12/// # Ok::<(), Box<dyn std::error::Error>>(())
13/// ```
14#[derive(Clone, Copy, Debug, Default)]
15pub struct Nop;
16
17impl Op for Nop {
18    type Output = ();
19
20    fn name(&self) -> &'static str {
21        "nop"
22    }
23
24    fn into_descriptor(self) -> Result<OpDescriptor> {
25        Ok(OpDescriptor::Nop)
26    }
27
28    fn map_completion(payload: CompletionPayload) -> Result<Self::Output> {
29        match payload {
30            CompletionPayload::Unit => Ok(()),
31            other => Err(crate::error::Error::completion(
32                format!("nop received unexpected completion payload: {other:?}"),
33                "ensure the backend routes nop completions as unit payloads",
34            )),
35        }
36    }
37}