use core::convert::Infallible;
pub trait Semigroup {
fn mappend(self, other: Self) -> Self;
}
#[cfg(feature = "std")]
impl<A> Semigroup for Vec<A> {
fn mappend(mut self, other: Self) -> Self {
self.extend(other);
self
}
}
#[cfg(feature = "std")]
impl Semigroup for String {
fn mappend(self, other: Self) -> Self {
self + &other
}
}
impl Semigroup for () {
fn mappend(self, _other: Self) -> Self {
()
}
}
impl Semigroup for Infallible {
fn mappend(self, _other: Self) -> Self {
unreachable!()
}
}
macro_rules! define_semigroup {
($type:ty) => {
impl Semigroup for $type {
fn mappend(self, other: Self) -> Self {
self + other
}
}
};
}
define_semigroup!(i8);
define_semigroup!(i16);
define_semigroup!(i32);
define_semigroup!(i64);
define_semigroup!(i128);
define_semigroup!(isize);
define_semigroup!(u8);
define_semigroup!(u16);
define_semigroup!(u32);
define_semigroup!(u64);
define_semigroup!(u128);
define_semigroup!(usize);