#![no_std]
pub extern crate alloc;
mod map;
#[macro_export]
#[doc(hidden)]
#[cfg(feature = "strict")]
macro_rules! non_strict {
( $($stuff:tt)* ) => {};
}
#[macro_export]
#[doc(hidden)]
#[cfg(not(feature = "strict"))]
macro_rules! non_strict {
(
#[doc = $doc:literal]
$($tail:tt)*
) => {
#[doc = concat!("[`non_strict`] ", $doc)]
$($tail)*
};
(
$($item:item)*
) => {
$(
#[doc = "[`non_strict`] "]
$item
)*
};
}
#[macro_export]
#[doc(hidden)]
macro_rules! btree_set_codegen {
{ $t:ident,
$(#[$meta:meta])*
$set:ident $($tail:tt)*
} => {
$(#[$meta])*
pub type $set = $crate::alloc::collections::BTreeSet<$t> ;
$crate::handle!{ $t $($tail)* }
};
}
#[macro_export]
#[doc(hidden)]
macro_rules! btree_map_codegen {
{ $t:ident,
$(#[$meta:meta])*
$map:ident $($tail:tt)*
} => {
$(#[$meta])*
pub type $map<T> = $crate::alloc::collections::BTreeMap<$t, T> ;
$crate::handle!{ $t $($tail)* }
};
}
#[macro_export]
#[doc(hidden)]
macro_rules! handle {
{ $t:ident, $(#[$meta:meta])* btree set: $($tail:tt)* } => {
$crate::btree_set_codegen! { $t, $(#[$meta])* $($tail)* }
};
{ $t:ident, $(#[$meta:meta])* btree map: $($tail:tt)* } => {
$crate::btree_map_codegen! { $t, $(#[$meta])* $($tail)* }
};
{ $t:ident, $(#[$meta:meta])* map: $($tail:tt)* } => {
$crate::map_codegen! { $t, $(#[$meta])* $($tail)* }
};
{ $t:ident $(,)? } => {};
{ $t:ident with iter: $iter:ident $($tail:tt)* } => {
compile_error!(concat!(
"maps do not have dedicated iterator structures anymore, remove `with iter: ",
stringify!($iter),
"` from your input",
));
};
{ $t:ident, range: $range:ident $($tail:tt)* } => {
compile_error!(concat!(
"`range` does not exist anymore, use `..` and `..=` operators instead and remove `range: ",
stringify!($range),
"` from your input",
));
};
{ $t:ident, $token:tt $($tail:tt)* } => {
compile_error!(concat!(
"expected `btree set`, `btree map` or `map` but found unexpected token `",
stringify!($token),
"`",
));
};
{ $t:ident $token:tt $($tail:tt)* } => {
compile_error!(concat!(
"expected comma, found unexpected token `",
stringify!($token),
"`",
));
};
}
#[macro_export]
macro_rules! new {
(
$(#[$meta:meta])*
$t:ident
$($tail:tt)*
) => (
$(#[$meta])*
#[derive(Debug, Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Hash)]
pub struct $t {
val: usize
}
impl $t {
$crate::non_strict! {
#[inline]
pub const fn new(val: usize) -> Self {
$t { val: val }
}
}
$crate::non_strict! {
#[inline]
pub const fn zero() -> Self {
$t { val: 0 }
}
}
$crate::non_strict! {
#[inline]
pub const fn one() -> Self {
$t { val: 1 }
}
}
$crate::non_strict! {
#[inline]
pub fn inc(&mut self) {
self.val += 1
}
}
$crate::non_strict! {
#[inline]
pub fn dec(&mut self) {
self.val -= 1
}
}
#[inline]
pub const fn get(& self) -> usize {
self.val
}
}
impl core::convert::Into<usize> for $t {
#[inline]
fn into(self) -> usize {
self.val
}
}
impl<'a> core::convert::Into<usize> for &'a $t {
#[inline]
fn into(self) -> usize {
self.val
}
}
impl core::ops::Deref for $t {
type Target = usize ;
#[inline]
fn deref(& self) -> & usize {
& self.val
}
}
impl core::fmt::Display for $t {
#[inline]
fn fmt(& self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result {
write!(fmt, "{}", self.val)
}
}
impl core::cmp::PartialEq<usize> for $t {
#[inline]
fn eq(& self, int: & usize) -> bool {
self.val.eq(int)
}
}
impl core::cmp::PartialOrd<usize> for $t {
#[inline]
fn partial_cmp(& self, int: & usize) -> Option<
core::cmp::Ordering
> {
self.val.partial_cmp(int)
}
}
$crate::non_strict! {
impl<T: core::convert::Into<usize>> core::ops::Add<T> for $t {
type Output = $t ;
#[inline]
fn add(mut self, rhs: T) -> $t {
self.val += rhs.into() ;
self
}
}
impl core::convert::From<usize> for $t {
#[inline]
fn from(val: usize) -> Self {
$t::new(val)
}
}
impl<'a> core::convert::From<&'a usize> for $t {
#[inline]
fn from(val: &'a usize) -> Self {
$t::new(* val)
}
}
impl<T: core::convert::Into<usize>> core::ops::AddAssign<T> for $t {
#[inline]
fn add_assign(&mut self, rhs: T) {
self.val += rhs.into()
}
}
impl Default for $t {
#[inline]
fn default() -> Self {
Self::zero()
}
}
}
$crate::handle!{ $t $($tail)* }
) ;
}
pub mod examples;