use crate::error::Result;
use crate::op::{CompletionPayload, Op, OpDescriptor};
#[derive(Clone, Copy, Debug)]
pub struct Cancel {
target: u64,
}
impl Cancel {
#[must_use]
pub fn new(target: u64) -> Self {
Self { target }
}
#[must_use]
pub fn target(self) -> u64 {
self.target
}
}
impl Op for Cancel {
type Output = ();
fn name(&self) -> &'static str {
"cancel"
}
fn into_descriptor(self) -> Result<OpDescriptor> {
Ok(OpDescriptor::Cancel {
target: self.target,
})
}
fn map_completion(payload: CompletionPayload) -> Result<Self::Output> {
match payload {
CompletionPayload::Unit => Ok(()),
other => Err(crate::error::Error::completion(
format!("cancel received unexpected completion payload: {other:?}"),
"ensure the backend routes cancel completions as unit payloads",
)),
}
}
}