1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use crate::ffvariants::{FallibleSelf, ImmutableSelf, InfallibleSelf, MutableSelf};
#[doc(hidden)]
#[derive(Debug, Clone, Copy)]
pub enum BuiltinTrait {
None,
Iterator,
}
mod private {
pub trait Sealed {}
}
pub trait BuiltinTraitFunction<S>: private::Sealed {
#[doc(hidden)]
const NAME: &'static str;
#[doc(hidden)]
fn owning_trait(&self) -> BuiltinTrait;
}
macro_rules! implement_builtin_trait_function {
($T:ty, $name:expr, ($($Args:ty),*), $owning_trait:expr) => {
impl super::private::Sealed for $T {}
macro_rules! implement_for {
(<$S:tt> $ST:ty) => {
impl<$S> BuiltinTraitFunction<$ST> for $T {
const NAME: &'static str = $name;
fn owning_trait(&self) -> BuiltinTrait {
$owning_trait
}
}
};
}
implement_for!(<S> FallibleSelf<ImmutableSelf<S>, (&S, $($Args),*)>);
implement_for!(<S> InfallibleSelf<ImmutableSelf<S>, (&S, $($Args),*)>);
implement_for!(<S> InfallibleSelf<MutableSelf<S>, (&mut S, $($Args),*)>);
implement_for!(<S> FallibleSelf<MutableSelf<S>, (&mut S, $($Args),*)>);
};
}
pub mod iterator {
use super::*;
#[derive(Debug)]
pub struct HasNext;
implement_builtin_trait_function!(HasNext, "has_next", (), BuiltinTrait::Iterator);
#[derive(Debug)]
pub struct Next;
implement_builtin_trait_function!(Next, "next", (), BuiltinTrait::Iterator);
}