1use std::ops::Add;
2
3pub trait Semigroup {
4 fn combine(self, other: Self) -> Self;
5}
6
7macro_rules! semigroup_numeric_impl {
8 ($($t:ty)*) => ($(
9 impl Semigroup for $t {
10 fn combine(self, other: Self) -> Self {
11 self + other
12 }
13 }
14 )*)
15}
16
17semigroup_numeric_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
18
19impl<T: Clone> Semigroup for Vec<T> {
20 fn combine(self, other: Self) -> Self {
21 let mut concat = self.to_vec();
22 concat.extend_from_slice(&other);
23 concat
24 }
25}
26
27impl Semigroup for String {
28 fn combine(self, other: Self) -> Self {
29 format!("{}{}", self, other)
30 }
31}