wireshift-core 0.1.1

Core typed operations, buffers, and backend traits for wireshift
Documentation
//! Implementation of a No-Op operation over the Ring instance.
use crate::error::Result;
use crate::op::{CompletionPayload, Op, OpDescriptor};

/// A no-op request useful for smoke tests and synchronization.
///
/// ```no_run
/// use wireshift::{Ring, RingConfig, ops::Nop};
///
/// let ring = Ring::new(RingConfig::default())?;
/// ring.submit(Nop)?.wait(None)?;
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
#[derive(Clone, Copy, Debug, Default)]
pub struct Nop;

impl Op for Nop {
    type Output = ();

    fn name(&self) -> &'static str {
        "nop"
    }

    fn into_descriptor(self) -> Result<OpDescriptor> {
        Ok(OpDescriptor::Nop)
    }

    fn map_completion(payload: CompletionPayload) -> Result<Self::Output> {
        match payload {
            CompletionPayload::Unit => Ok(()),
            other => Err(crate::error::Error::completion(
                format!("nop received unexpected completion payload: {other:?}"),
                "ensure the backend routes nop completions as unit payloads",
            )),
        }
    }
}