1#![no_std]
2#![doc = include_str!("../README.md")]
3
4macro_rules! impl_shorts {
5 ($vis:vis impl$([$($g:tt)*])?$(($($aty:ident),*))?
6 $name:ident $(: $namedep:path $(: $namedeprest:path)*)?
7 => $dname:literal : $ty:ty
8 $(where $($wty:ty : $wbf:path $(: $wbr:path)*),+ $(,)?)?
9 {$(
10 fn $short:ident : $long:ident
11 ($($param:tt)*)
12 $(-> $retty:ty)?
13 $([$($mg:tt)*])?
14 $(where $($mwty:ty : $mwbf:path $(: $mwbr:path)*),+ $(,)?)?
15 );* $(;)?}) => {
16 $vis trait $name $(: $namedep $(+ $namedeprest)*)? {
17 $($(type $aty;)*)?
18 $(
19 #[doc = concat!(
20 "Map to [`", $dname, "::", stringify!($long), "`]",
21 )]
22 #[stringify_inner::sexpr_attr(doc(alias = #stringify($long)))]
23 fn $short
24 $(<$($mg)*>)?
25 ($($param)*) $(-> $retty)?
26 $(where $($mwty: $mwbf $(+ $mwbr)*,)+)?
27 ;
28 )*
29 }
30 impl<$($($g)*)?> $name for $ty
31 $(where $($wty: $wbf $(+ $wbr)*,)+)?
32 {
33 $($(type $aty = $aty;)*)?
34 $(
35 fn $short
36 $(<$($mg)*>)?
37 ($($param)*) $(-> $retty)?
38 $(where $($mwty: $mwbf $(+ $mwbr)*,)+)?
39 {
40 impl_shorts!(@impl($long => $($param)*) $($param)*)
41 }
42 )*
43 }
44 };
45 (@impl($long:ident => self: $sty:ty $(, $($_t:tt)*)?) $self:ident : $sty1:ty $(, $name:ident : $ty:ty)* $(,)?) => {
46 Self::$long($self $(, $name)*)
47 };
48 (@impl($long:ident => self $($_t:tt)*) $self:ident $(, $name:ident : $ty:ty)* $(,)?) => {
49 Self::$long($self $(, $name)*)
50 };
51 (@impl($long:ident => &self $($_t:tt)*) &$self:ident $(, $name:ident : $ty:ty)* $(,)?) => {
52 Self::$long($self $(, $name)*)
53 };
54 (@impl($long:ident => &mut self $($_t:tt)*) &mut $self:ident $(, $name:ident : $ty:ty)* $(,)?) => {
55 Self::$long($self $(, $name)*)
56 };
57}
58
59mod option;
60mod result;
61mod iter;
62
63pub use option::*;
64pub use result::*;
65pub use iter::*;
66
67#[cfg(test)]
68mod tests {
69 use super::*;
70
71 #[test]
72 fn it_works() {
73 let mut a = Some { 0: &mut 8 };
74 let _: Option<&mut i32> = a.adm();
75 let _: Option<&i32> = a.ad();
76 }
77}