ice-rpc 0.2.2

Zero-copy RPC over iceoryx2 with automatic reconnection, service discovery and HTTP gateway
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
//! Fundamental types of the ice-rpc RPC protocol.
//!
//! This module defines:
//! - The node identity ([`NodeId`])
//! - The zero-copy RPC header ([`RpcHeader`])
//! - The stream events ([`Event`], `Observable`)
//! - The RPC errors ([`RpcError`], [`TakeOneError`])
//! - The tuning constants (timeouts, buffer sizes, etc.)

use iceoryx2::prelude::*;
pub use iceoryx2_bb_container::string::StaticString;
use rkyv::{Archive, Deserialize, Serialize};

/// Compact identifier of an ice-rpc node on the iceoryx2 bus.
///
/// Corresponds to the PID of the host process, guaranteeing uniqueness
/// across processes on the same machine.
#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, ZeroCopySend, Default)]
pub struct NodeId(pub u32);

impl NodeId {
    /// Creates a [`NodeId`] from the current process PID.
    #[inline]
    pub fn current() -> Self {
        Self(std::process::id())
    }
}

impl std::fmt::Display for NodeId {
    #[inline]
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "node-{}", self.0)
    }
}

/// Event emitted by an RPC stream.
#[derive(Archive, Serialize, Deserialize, Debug, Clone)]
pub enum Event<T, E> {
    /// Intermediate business value.
    Next(T),
    /// Normal end of the stream.
    Complete,
    /// Business error.
    Error(E),
    /// Technical RPC error (e.g. incompatible version), terminal.
    RpcError(RpcError),
}

/// Alias for the return type of methods generated by `#[service]`.
pub type Observable<T, E> = Result<Stream<T, E>, RpcError>;

/// Sender of RPC events (multi-producer, runtime-agnostic).
pub type Sender<T, E> = async_channel::Sender<Event<T, E>>;

/// Alias for the receiver of RPC events (runtime-agnostic).
pub type Stream<T, E> = async_channel::Receiver<Event<T, E>>;

/// Creates a bounded channel of RPC events.
///
/// Runtime-agnostic replacement for `tokio::sync::mpsc::channel`.
pub fn channel<T, E>(capacity: usize) -> (Sender<T, E>, Stream<T, E>) {
    async_channel::bounded(capacity)
}

/// Maximum size of a method name in the RPC header.
/// Must match the private `METHOD_NAME_LEN` constant in `ice-rpc-macros`.
pub const METHOD_NAME_LEN: usize = 64;

/// Maximum size of a service name in the RPC header.
/// Must match the private `SERVICE_NAME_LEN` constant in `ice-rpc-macros`.
pub const SERVICE_NAME_LEN: usize = 64;

/// Version of the ice-rpc wire protocol carried in [`RpcHeader`].
///
/// Bumped whenever the layout of [`RpcHeader`] or the request/response
/// encoding changes. A peer with a different value is rejected before any
/// deserialization takes place.
pub const PROTOCOL_VERSION: u16 = 1;

/// Threshold above which a payload is published on the `_large` topic.
pub const LARGE_PAYLOAD_THRESHOLD: usize = 1024;

/// Returns the `"default"` topic name for a given node.
pub fn node_default_topic(node_id: NodeId) -> String {
    format!("node_{}_default", node_id.0)
}

/// Returns the `"large"` topic name for a given node.
pub fn node_large_topic(node_id: NodeId) -> String {
    format!("node_{}_large", node_id.0)
}

/// Returns the `"notify"` topic name for a given node.
pub fn node_notify_topic(node_id: NodeId) -> String {
    format!("node_{}_notify", node_id.0)
}

/// Maximum timeout for a single RPC call (seconds).
pub const RPC_CALL_TIMEOUT_SECS: u64 = 30;

/// Initial slice size for iceoryx2 publishers (`_default` topics).
///
/// This is the fallback used when the `#[service]` macro does not override it
/// through `default_size_message`.
pub const PUBLISHER_DEFAULT_MAX_SLICE_LEN: usize = 256;
/// Initial slice size for iceoryx2 publishers (`_large` topics).
pub const PUBLISHER_LARGE_MAX_SLICE_LEN: usize = 4096;

/// WaitSet timeout (ms) for the hub dispatch loop.
pub const WAITSET_TIMEOUT_US: u64 = 500;
/// Poll interval (ms) while locating a service on the client side.
pub const SERVER_READY_POLL_MS: u64 = 100;
/// Retry interval (ms) for service initialization.
pub const INIT_RETRY_INTERVAL_MS: u64 = 1_000;

/// Global timeout (seconds) for [`initialize_all`](crate::ServiceLocator::initialize_all).
pub const INITIALIZE_ALL_TIMEOUT_SECS: u16 = 30;

/// Maximum number of readers on a Blackboard.
pub const BLACKBOARD_MAX_READERS: usize = 64;

/// Subscriber buffer size for the `_default` topics.
pub const DEFAULT_TOPIC_BUFFER_SIZE: usize = 4096;

/// Subscriber buffer size for the `_large` topics.
///
pub const LARGE_TOPIC_BUFFER_SIZE: usize = 4;

// ---------------------------------------------------------------------------
// Types for the discovery registry (1 Blackboard per node)
// ---------------------------------------------------------------------------

/// Maximum number of services per node (= number of keys in the Blackboard).
pub const MAX_SERVICES_PER_NODE: usize = 32;
/// Max size of a service name used as a key in the Blackboard.
pub const REGISTRY_SERVICE_NAME_LEN: usize = 64;

/// Discriminant of the RPC event type carried in the [`RpcHeader`].
///
/// `#[repr(C)]` is required by `ZeroCopySend`. The values are fixed.
#[repr(C)]
#[derive(
    Debug, Clone, Copy, PartialEq, Eq, ZeroCopySend, Default, Archive, Serialize, Deserialize,
)]
pub enum EventKind {
    /// Request emitted by the client (non-terminal).
    #[default]
    Request = 0,
    /// Intermediate event carrying a business value.
    Next = 1,
    /// Normal end of the stream (terminal).
    Complete = 2,
    /// Business error (terminal).
    Error = 3,
}

impl EventKind {
    /// Returns `true` if this event terminates the stream.
    #[inline]
    pub fn is_terminal(self) -> bool {
        matches!(self, EventKind::Complete | EventKind::Error)
    }
}

/// Zero-copy iceoryx2 header carried in the `user_header` of each sample.
///
/// Multiplexes several services on the same topics via the `service_name` field.
#[repr(C)]
#[derive(Debug, Clone, Copy, ZeroCopySend, Default)]
pub struct RpcHeader {
    /// Request↔response correlation UUID (128 bits).
    pub correlation_id: [u8; 16],
    /// Emission timestamp in nanoseconds since `UNIX_EPOCH`.
    pub sent_at_ns: u64,
    /// PID of the emitting process.
    pub caller_pid: u32,
    /// Name of the target service.
    pub service_name: StaticString<SERVICE_NAME_LEN>,
    /// Name of the RPC method.
    pub method_name: StaticString<METHOD_NAME_LEN>,
    /// Type of the carried event.
    pub event_kind: EventKind,
    /// Version of the ice-rpc wire protocol.
    pub protocol_version: u16,
    /// Version of the service interface (methods + request enum).
    pub service_version: u16,
}

impl RpcHeader {
    /// Creates a **request** header with a unique correlation_id and the current timestamp.
    pub fn new(service: &str, method: &str) -> Self {
        Self {
            correlation_id: RpcHeader::next_correlation_id(),
            sent_at_ns: RpcHeader::now_ns(),
            caller_pid: std::process::id(),
            service_name: StaticString::from_bytes_truncated(service.as_bytes())
                .unwrap_or_default(),
            method_name: StaticString::from_bytes_truncated(method.as_bytes()).unwrap_or_default(),
            event_kind: EventKind::Request,
            protocol_version: PROTOCOL_VERSION,
            service_version: 0,
        }
    }

    /// Sets the service interface version carried in the header.
    #[inline]
    pub fn with_service_version(mut self, service_version: u16) -> Self {
        self.service_version = service_version;
        self
    }

    /// Creates a **request** header with a service interface version.
    #[inline]
    pub fn request(service: &str, method: &str, service_version: u16) -> Self {
        Self::new(service, method).with_service_version(service_version)
    }

    /// Creates a **response** header from a request header.
    ///
    /// Reuses the correlation id, service and method names of the request and
    /// stamps the protocol/service versions and the current timestamp.
    #[inline]
    pub fn response_from(request: &RpcHeader, event_kind: EventKind, service_version: u16) -> Self {
        Self {
            correlation_id: request.correlation_id,
            sent_at_ns: RpcHeader::now_ns(),
            caller_pid: std::process::id(),
            service_name: request.service_name,
            method_name: request.method_name,
            event_kind,
            protocol_version: PROTOCOL_VERSION,
            service_version,
        }
    }

    /// Returns `true` if this header is a request (client → server).
    #[inline]
    pub fn is_request(&self) -> bool {
        self.event_kind == EventKind::Request
    }

    /// Returns `true` if this header is a response (server → client).
    #[inline]
    pub fn is_response(&self) -> bool {
        self.event_kind != EventKind::Request
    }

    /// Returns the service name as a `&str`.
    #[inline]
    pub fn service(&self) -> &str {
        core::str::from_utf8(self.service_name.as_bytes_const()).unwrap_or("")
    }

    /// Generates a unique correlation id without a CSPRNG syscall.
    ///
    /// Layout of the 16 bytes:
    /// - `[0..4]`   : PID (u32 LE) — cross-process uniqueness.
    /// - `[4..12]`  : atomic counter u64 LE — intra-process uniqueness.
    /// - `[12..16]` : padding (zeros).
    pub fn next_correlation_id() -> [u8; 16] {
        use std::sync::atomic::{AtomicU64, Ordering};
        static COUNTER: AtomicU64 = AtomicU64::new(1);
        let seq = COUNTER.fetch_add(1, Ordering::Relaxed);
        let pid = std::process::id();
        let mut id = [0u8; 16];
        id[0..4].copy_from_slice(&pid.to_le_bytes());
        id[4..12].copy_from_slice(&seq.to_le_bytes());
        id
    }

    /// Returns the method name as a `&str`.
    #[inline]
    pub fn method(&self) -> &str {
        core::str::from_utf8(self.method_name.as_bytes_const()).unwrap_or("")
    }

    /// Returns the current timestamp in nanoseconds since `UNIX_EPOCH`.
    pub fn now_ns() -> u64 {
        std::time::SystemTime::now()
            .duration_since(std::time::UNIX_EPOCH)
            .map(|d| d.as_nanos() as u64)
            .unwrap_or(0)
    }
}

/// Extracts the emitting PID from a raw `correlation_id`.
#[inline]
pub fn caller_pid_from_cid(cid: &[u8; 16]) -> u32 {
    u32::from_le_bytes([cid[0], cid[1], cid[2], cid[3]])
}

/// Formats a correlation id as hexadecimal (UUID-like format).
pub fn fmt_correlation_id(cid: &[u8; 16]) -> String {
    let [b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15] = cid;
    format!(
        "{:02x}{:02x}{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}",
        b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15,
    )
}

/// Formats the first 4 bytes of a correlation_id in hex (8 characters).
///
/// These 4 bytes contain the PID of the emitting process.
pub fn fmt_correlation_id_short(cid: &[u8; 16]) -> String {
    format!("{:02x}{:02x}{:02x}{:02x}", cid[0], cid[1], cid[2], cid[3])
}

/// Technical RPC error, categorized so callers can choose a policy
/// (retry / fallback / log / fatal) via [`RpcError::is_retryable`].
#[derive(Debug, Clone, Archive, Serialize, Deserialize, thiserror::Error)]
pub enum RpcError {
    /// Payload serialization/deserialization failure.
    #[error("RPC error: serialization failure")]
    SerializationError,
    /// iceoryx2 transport failure (loan, send, receive, publisher creation).
    #[error("RPC transport error: {0}")]
    TransportError(String),
    /// Service discovery failed (registry/blackboard unavailable).
    #[error("RPC discovery error: {0}")]
    DiscoveryError(String),
    /// The requested service is not registered on any node.
    #[error("RPC service not found: {service}")]
    ServiceNotFound { service: String },
    /// The provider node is unreachable (publishers missing/invalidated).
    #[error("RPC provider unavailable (node {node})")]
    ProviderUnavailable { node: u32 },
    /// Waiting deadline exceeded.
    #[error("RPC error: timeout exceeded")]
    Timeout,
    /// The call was cancelled by a global shutdown (Ctrl+C).
    #[error("RPC error: call cancelled")]
    Cancelled,
    /// Payload exceeds the configured shared-memory limit.
    #[error("RPC payload too large: {size} bytes (limit {limit})")]
    PayloadTooLarge { size: usize, limit: usize },
    /// Peer uses an incompatible protocol or service version.
    #[error(
        "RPC protocol mismatch (protocol {received_protocol} != {expected_protocol}, service {received_service} != {expected_service})"
    )]
    ProtocolMismatch {
        expected_protocol: u16,
        received_protocol: u16,
        expected_service: u16,
        received_service: u16,
    },
    /// Unexpected internal error / invariant violation.
    #[error("RPC internal error: {0}")]
    Internal(String),
}

impl RpcError {
    /// Returns `true` when retrying the same call may succeed.
    ///
    /// Transient failures (transport, discovery, provider availability,
    /// timeout) are retryable. Deterministic failures (serialization, missing
    /// service, payload size, protocol mismatch) and internal errors are not.
    pub fn is_retryable(&self) -> bool {
        matches!(
            self,
            RpcError::TransportError(_)
                | RpcError::DiscoveryError(_)
                | RpcError::ProviderUnavailable { .. }
                | RpcError::Timeout
        )
    }
}

/// Error returned by `take_one`.
///
/// Distinguishes a technical IPC error from an application business error.
#[derive(Debug, thiserror::Error)]
pub enum TakeOneError<E: std::fmt::Display> {
    /// Technical IPC error before receiving an event.
    #[error("IPC error: {0}")]
    Ipc(RpcError),
    /// Business error returned by the service through `Event::Error(e)`.
    #[error("Service error: {0}")]
    Service(E),
    /// The stream ended without emitting a value.
    #[error("Stream closed without a value")]
    Empty,
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn event_kind_request_is_not_terminal() {
        assert!(!EventKind::Request.is_terminal());
    }

    #[test]
    fn event_kind_next_is_not_terminal() {
        assert!(!EventKind::Next.is_terminal());
    }

    #[test]
    fn event_kind_complete_is_terminal() {
        assert!(EventKind::Complete.is_terminal());
    }

    #[test]
    fn event_kind_error_is_terminal() {
        assert!(EventKind::Error.is_terminal());
    }

    #[test]
    fn event_kind_default_is_request() {
        assert_eq!(EventKind::default(), EventKind::Request);
    }

    #[test]
    fn event_kind_discriminants() {
        assert_eq!(EventKind::Request as u8, 0);
        assert_eq!(EventKind::Next as u8, 1);
        assert_eq!(EventKind::Complete as u8, 2);
        assert_eq!(EventKind::Error as u8, 3);
    }

    #[test]
    fn rpc_header_new_populates_correlation_id() {
        let header = RpcHeader::new("test_svc", "test_method");
        assert_ne!(header.correlation_id, [0u8; 16]);
    }

    #[test]
    fn rpc_header_new_sets_service_and_method() {
        let header = RpcHeader::new("MyService", "hello_world");
        assert_eq!(header.service(), "MyService");
        assert_eq!(header.method(), "hello_world");
    }

    #[test]
    fn rpc_header_new_event_kind_is_request() {
        let header = RpcHeader::new("any_svc", "any");
        assert_eq!(header.event_kind, EventKind::Request);
    }

    #[test]
    fn rpc_header_new_sets_protocol_version() {
        let header = RpcHeader::new("svc", "m");
        assert_eq!(header.protocol_version, PROTOCOL_VERSION);
        assert_eq!(header.service_version, 0);
    }

    #[test]
    fn rpc_header_with_service_version() {
        let header = RpcHeader::new("svc", "m").with_service_version(7);
        assert_eq!(header.service_version, 7);
    }

    #[test]
    fn rpc_header_new_sent_at_ns_is_nonzero() {
        let header = RpcHeader::new("svc", "test");
        assert!(header.sent_at_ns > 0);
    }

    #[test]
    fn next_correlation_id_is_unique() {
        let id1 = RpcHeader::next_correlation_id();
        let id2 = RpcHeader::next_correlation_id();
        assert_ne!(id1, id2);
    }

    #[test]
    fn next_correlation_id_pid_field() {
        let id = RpcHeader::next_correlation_id();
        let pid = u32::from_le_bytes([id[0], id[1], id[2], id[3]]);
        assert_eq!(pid, std::process::id());
    }

    #[test]
    fn rpc_header_method_empty_on_default() {
        let header = RpcHeader::default();
        assert!(header.method().is_empty());
    }

    #[test]
    fn rpc_header_method_truncated_on_long_name() {
        let long_name = "a".repeat(METHOD_NAME_LEN + 50);
        let header = RpcHeader::new("svc", &long_name);
        assert!(header.method().len() <= METHOD_NAME_LEN);
    }

    #[test]
    fn now_ns_returns_reasonable_value() {
        let ns = RpcHeader::now_ns();
        assert!(ns > 1_500_000_000_000_000_000);
    }

    #[test]
    fn now_ns_is_monotonic() {
        let t1 = RpcHeader::now_ns();
        let t2 = RpcHeader::now_ns();
        assert!(t2 >= t1);
    }

    #[test]
    fn fmt_correlation_id_format_length() {
        let cid = [
            0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E,
            0x0F, 0x10,
        ];
        let formatted = fmt_correlation_id(&cid);
        assert_eq!(formatted.len(), 36);
    }

    #[test]
    fn fmt_correlation_id_contains_dashes() {
        let cid = [0xAA; 16];
        let formatted = fmt_correlation_id(&cid);
        assert!(formatted.contains('-'));
        assert_eq!(formatted.matches('-').count(), 4);
    }

    #[test]
    fn fmt_correlation_id_stable_output() {
        let cid = [
            0xDE, 0xAD, 0xBE, 0xEF, 0xCA, 0xFE, 0xBA, 0xBE, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55,
            0x66, 0x77,
        ];
        let expected = "deadbeef-cafe-babe-0011-223344556677";
        assert_eq!(fmt_correlation_id(&cid), expected);
    }

    #[test]
    fn fmt_correlation_id_short_length() {
        let cid = [
            0x01, 0x02, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00,
        ];
        let formatted = fmt_correlation_id_short(&cid);
        assert_eq!(formatted.len(), 8);
    }

    #[test]
    fn fmt_correlation_id_short_first_four_bytes() {
        let cid = [
            0x12, 0x34, 0x56, 0x78, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
            0xFF, 0xFF,
        ];
        let formatted = fmt_correlation_id_short(&cid);
        assert_eq!(formatted, "12345678");
    }

    #[test]
    fn rpc_error_display_serialization_error() {
        let err = RpcError::SerializationError;
        assert!(err.to_string().contains("serialization"));
    }

    #[test]
    fn rpc_error_display_transport_error() {
        let err = RpcError::TransportError("connection refused".into());
        assert!(err.to_string().contains("connection refused"));
    }

    #[test]
    fn rpc_error_display_timeout() {
        let err = RpcError::Timeout;
        assert!(err.to_string().contains("timeout"));
    }

    #[test]
    fn rpc_error_protocol_mismatch_display() {
        let err = RpcError::ProtocolMismatch {
            expected_protocol: 1,
            received_protocol: 2,
            expected_service: 3,
            received_service: 4,
        };
        assert!(err.to_string().contains("protocol mismatch"));
    }

    #[test]
    fn rpc_error_is_retryable_classification() {
        assert!(RpcError::TransportError("boom".into()).is_retryable());
        assert!(RpcError::DiscoveryError("boom".into()).is_retryable());
        assert!(RpcError::ProviderUnavailable { node: 1 }.is_retryable());
        assert!(RpcError::Timeout.is_retryable());

        assert!(!RpcError::SerializationError.is_retryable());
        assert!(!RpcError::ServiceNotFound {
            service: "svc".into()
        }
        .is_retryable());
        assert!(!RpcError::Cancelled.is_retryable());
        assert!(!RpcError::PayloadTooLarge {
            size: 1,
            limit: 1
        }
        .is_retryable());
        assert!(!RpcError::Internal("boom".into()).is_retryable());
    }

    #[test]
    fn take_one_error_ipc_contains_message() {
        let err = TakeOneError::<String>::Ipc(RpcError::Timeout);
        assert!(err.to_string().contains("timeout"));
    }

    #[test]
    fn take_one_error_service_contains_value() {
        let err = TakeOneError::Service("not found".to_string());
        assert!(err.to_string().contains("not found"));
    }

    #[test]
    fn take_one_error_empty_message() {
        let err = TakeOneError::<String>::Empty;
        assert!(!err.to_string().is_empty());
    }
}