is_sus/lib.rs
1//! A library to detect if a type is suspicious or not.
2//! Similar usage to [is-odd](https://lib.rs/is-odd).
3//!
4//! Example
5//! ```
6//! use is_sus::{Impostor, IsSus};
7//! fn main() {
8//! println!("sus = {}", Impostor.is_sus());
9//! }
10//! ```
11
12#[cfg(test)]
13mod tests;
14
15/// Trait to check if a type is sus
16pub trait IsSus {
17 /// Check if this type is sus
18 fn is_sus(&self) -> bool;
19}
20
21/// A crewmate, which can be red or not red.
22/// Red is always sus.
23pub struct Crewmate {
24 pub is_red: bool
25}
26
27impl IsSus for Crewmate {
28 fn is_sus(&self) -> bool {
29 // red is always sus
30 self.is_red
31 }
32}
33
34/// An impostor, acting sus as usual.
35pub struct Impostor;
36
37impl IsSus for Impostor {
38 fn is_sus(&self) -> bool {
39 true
40 }
41}
42
43/// Common usecase - sus anything we don't know
44impl IsSus for i32 {
45 fn is_sus(&self) -> bool {
46 *self < 0
47 }
48}