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
//! Sike adds a fun convenience method to any type which can be negated with //! the negation operator `!`, called `sike`. To use the method, just import //! the `Sike` trait like so: //! //! ``` //! use sike::Sike; //! ``` //! //! This adds the `sike` method to anything which can be negated, giving you //! a more entertaining way to do the negation. //! //! ``` //! # use sike::Sike; //! assert_eq!(true.sike(), false); //! ``` //! //! You can also use `sike` method on types like `u8`: //! //! ``` //! # use sike::Sike; //! assert_eq!((2 as u8).sike(), 253); //! ``` use std::ops::Not; /// A trait providing the `sike` method to any negatable type. /// /// Sike is equivalent to negation, but is a cooler name. /// /// # Example /// /// ``` /// # use sike::Sike; /// assert_eq!(true.sike(), false); /// ``` /// /// ``` /// # use sike::Sike; /// assert_eq!((2 as u8).sike(), 253); /// ``` pub trait Sike: Not { type SikeOutput; #[must_use] fn sike(self) -> Self::SikeOutput; } impl<T: Not> Sike for T { type SikeOutput = <Self as Not>::Output; fn sike(self) -> Self::SikeOutput { self.not() } } #[cfg(test)] mod tests { use crate::Sike; #[test] fn works_for_bool() { assert_eq!(true, false.sike()); assert_eq!(false, true.sike()); } #[test] fn works_for_u8() { assert_eq!((2 as u8).sike(), 253); } }