gcollections/ops/
cardinality.rs1use num_traits::{One, Zero, Unsigned};
10use num_integer::{Integer};
11
12pub trait Cardinality
13{
14 type Size: Unsigned + Integer;
15 fn size(&self) -> Self::Size;
16}
17
18pub trait IsSingleton
19{
20 fn is_singleton(&self) -> bool;
21}
22
23pub trait IsEmpty
24{
25 fn is_empty(&self) -> bool;
26}
27
28macro_rules! is_singleton_impl
31{
32 ( $( $keyword:tt ),*) =>
33 {
34 impl<R> IsSingleton for R where
35 R: Cardinality
36 {
37 $($keyword)* fn is_singleton(&self) -> bool {
38 self.size() == <<Self as Cardinality>::Size as One>::one()
39 }
40 }
41 }
42}
43
44#[cfg(feature = "nightly")]
45is_singleton_impl!(default);
46#[cfg(not(feature = "nightly"))]
47is_singleton_impl!();
48
49macro_rules! is_empty_impl
50{
51 ( $( $keyword:tt ),*) =>
52 {
53 impl <R> IsEmpty for R where
54 R: Cardinality
55 {
56 $($keyword)* fn is_empty(&self) -> bool {
57 self.size().is_zero()
58 }
59 }
60 }
61}
62
63#[cfg(feature = "nightly")]
64is_empty_impl!(default);
65#[cfg(not(feature = "nightly"))]
66is_empty_impl!();