use std::time::Duration;
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct SenderId(pub u64);
impl std::fmt::Display for SenderId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "SenderId({})", self.0)
}
}
#[derive(Debug, Clone, Default)]
pub struct MpscAnchorConfig {
pub unattached_timeout: Option<Duration>,
pub heartbeat_interval: Option<Duration>,
pub max_senders: Option<usize>,
pub channel_capacity: Option<usize>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn sender_id_display() {
let sid = SenderId(42);
assert_eq!(format!("{sid}"), "SenderId(42)");
assert_eq!(format!("{sid:?}"), "SenderId(42)");
}
#[test]
fn sender_id_ordering() {
let a = SenderId(1);
let b = SenderId(2);
assert!(a < b);
assert_eq!(a, SenderId(1));
assert_ne!(a, b);
}
#[test]
fn mpsc_anchor_config_default() {
let cfg = MpscAnchorConfig::default();
assert!(cfg.unattached_timeout.is_none());
assert!(cfg.heartbeat_interval.is_none());
assert!(cfg.max_senders.is_none());
assert!(cfg.channel_capacity.is_none());
}
#[test]
fn mpsc_anchor_config_override_all_fields() {
let cfg = MpscAnchorConfig {
unattached_timeout: Some(Duration::from_secs(1)),
heartbeat_interval: Some(Duration::from_millis(100)),
max_senders: Some(8),
channel_capacity: Some(512),
};
assert_eq!(cfg.unattached_timeout, Some(Duration::from_secs(1)));
assert_eq!(cfg.heartbeat_interval, Some(Duration::from_millis(100)));
assert_eq!(cfg.max_senders, Some(8));
assert_eq!(cfg.channel_capacity, Some(512));
let cfg2 = cfg.clone();
assert_eq!(cfg2.max_senders, Some(8));
}
}