use crate::task::Value;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct DroppedSentinel;
pub fn is_dropped(value: &dyn Value) -> bool {
value.as_any().downcast_ref::<DroppedSentinel>().is_some()
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct PassthroughSentinel;
pub fn is_passthrough(value: &dyn Value) -> bool {
value
.as_any()
.downcast_ref::<PassthroughSentinel>()
.is_some()
}
#[cfg(test)]
mod tests {
use super::*;
use std::sync::Arc;
#[test]
fn detects_dropped_sentinel() {
let v: Arc<dyn Value> = Arc::new(DroppedSentinel);
assert!(is_dropped(v.as_ref()));
}
#[test]
fn ignores_regular_value() {
let v: Arc<dyn Value> = Arc::new(42_usize);
assert!(!is_dropped(v.as_ref()));
}
#[test]
fn ignores_boxed_regular_value() {
let v: Box<dyn Value> = Box::new(99_i32);
assert!(!is_dropped(v.as_ref()));
}
#[test]
fn detects_boxed_dropped_sentinel() {
let v: Box<dyn Value> = Box::new(DroppedSentinel);
assert!(is_dropped(v.as_ref()));
}
#[test]
fn detects_passthrough_sentinel() {
let v: Arc<dyn Value> = Arc::new(PassthroughSentinel);
assert!(is_passthrough(v.as_ref()));
}
#[test]
fn passthrough_ignores_regular_value() {
let v: Arc<dyn Value> = Arc::new(42_usize);
assert!(!is_passthrough(v.as_ref()));
}
#[test]
fn passthrough_ignores_dropped_sentinel() {
let v: Arc<dyn Value> = Arc::new(DroppedSentinel);
assert!(!is_passthrough(v.as_ref()));
}
}