use generate_sets::*;
use std::{any::TypeId, convert::Infallible};
#[diagnostic::on_unimplemented(
message = "`{Self}` does not contain `{E}`",
label = "type does not contain this element",
note = "a type implements `Contains<E>` when `E` is one of its set members"
)]
pub trait Contains<E>: Contains0 {}
#[diagnostic::do_not_recommend]
impl<E, T: ?Sized> Contains<E> for T where T: Contains1<E> {}
#[diagnostic::on_unimplemented(
message = "`{Self}` is not a subset of `{S}`",
label = "this set is not a subset of the required set",
note = "every member of the left-hand set must also be present in the right-hand set"
)]
pub trait Subset<S: ?Sized> {}
#[diagnostic::do_not_recommend]
impl<T, R> Subset<R> for T
where
T: AsTypeSet<Set: Subset<R::Set>>,
R: AsTypeSet,
{
}
#[diagnostic::on_unimplemented(
message = "`{Self}` is not a superset of `{S}`",
label = "this set does not contain all required members",
note = "every member of the right-hand set must also be present in the left-hand set"
)]
pub trait Superset<S: ?Sized> {}
#[diagnostic::do_not_recommend]
impl<S1: ?Sized, S2: ?Sized> Superset<S2> for S1 where S2: Subset<S1> {}
pub trait AsTypeSet {
type Set: ?Sized;
}
pub trait Members {
fn members() -> &'static [TypeId];
}
impl<T> Members for T
where
T: AsTypeSet<Set: Members>,
{
fn members() -> &'static [TypeId] {
<T::Set as Members>::members()
}
}
#[diagnostic::on_unimplemented(
message = "`{Self}` and `{R}` do not represent the same set",
label = "the sets contain different members",
note = "two sets are equal when every member of one is also a member of the other"
)]
pub trait SetEqual<R: ?Sized> {}
pub trait IsEmpty: Subset<()> {}
impl<T> IsEmpty for T where T: Subset<()> {}
pub trait Push {
type Output<E>;
}
pub type Insert<T, E> = <T as Push>::Output<E>;
#[diagnostic::do_not_recommend]
impl<T: AsTypeSet, R: AsTypeSet> SetEqual<R> for T where T: Subset<R> + Superset<R> {}
mod generate_sets;
pub use union::*;
mod union;
#[cfg(feature = "assertions")]
pub mod assert {
use super::*;
pub fn eq<T, R>()
where
T: SetEqual<R>,
{
}
pub fn superset<T, R>()
where
T: Superset<R>,
{
}
pub fn subset<T, R>()
where
T: Subset<R>,
{
}
pub fn contains<T, E>()
where
T: Contains<E>,
{
}
pub fn is_empty<T>()
where
T: IsEmpty,
{
}
}