object_transfer/unsub_noop.rs
1//! A no-operation unsubscribe implementation.
2//!
3//! This module provides a no-op implementation of the unsubscribe trait,
4//! useful for scenarios where unsubscribe operations are not needed or
5//! should be skipped without performing any actual work.
6
7use async_trait::async_trait;
8
9use crate::errors::UnSubError;
10use crate::traits::UnSubTrait;
11
12/// A no-operation unsubscribe handler.
13///
14/// `UnSubNoop` is a simple implementation of [`UnSubTrait`]
15/// that performs no operations when unsubscribe is called.
16///
17/// Depending on how it is configured, `unsubscribe` will either:
18/// - Return `Ok(())` without taking any action when `should_err` is `false`
19/// - Return `Err(UnSubError::NoHandler)` when `should_err` is `true`
20///
21/// This is useful for:
22/// - Default implementations where unsubscribe is not required
23/// - Testing and mocking scenarios
24/// - Cases where subscription cleanup is not necessary
25pub struct UnSubNoop {
26 should_err: bool,
27}
28
29impl UnSubNoop {
30 /// Creates a new instance of `UnSubNoop`.
31 pub fn new(should_err: bool) -> Self {
32 UnSubNoop { should_err }
33 }
34}
35
36#[async_trait]
37impl UnSubTrait for UnSubNoop {
38 /// Performs a no-operation unsubscribe.
39 ///
40 /// Returns `Err(UnSubError::NoHandler)` if `should_err` is `true`,
41 /// otherwise returns `Ok(())`.
42 ///
43 /// # Returns
44 ///
45 /// Returns `Err(UnSubError::NoHandler)` if `should_err` is `true`,
46 /// otherwise returns `Ok(())`.
47 async fn unsubscribe(&self) -> Result<(), UnSubError> {
48 if self.should_err {
49 return Err(UnSubError::NoHandler);
50 }
51 Ok(())
52 }
53}