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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//! Examples of [`#[sabi_trait]`](macro@crate::sabi_trait)
//! generated trait objects,for the documentation.

use crate::sabi_trait;

#[sabi_trait]
/// An example trait, used to show what [`#[sabi_trait]`](macro@crate::sabi_trait)
/// generates in the docs.
#[sabi(use_dyn_trait)]
pub trait ConstExample: Debug + Clone {
    ///
    #[sabi(last_prefix_field)]
    fn next_number(&self, num: usize) -> usize;
}

impl ConstExample for usize {
    fn next_number(&self, num: usize) -> usize {
        self + num
    }
}

#[sabi_trait]
// #[sabi(debug_print_trait)]
/// An example trait object that uses `RObject` as a backend.
pub trait Doer: Debug {
    ///
    fn value(&self) -> usize;

    ///
    fn do_it(&self, num: usize) -> usize;

    ///
    #[sabi(last_prefix_field)]
    fn add_into(&mut self, num: usize);
}

impl Doer for usize {
    fn value(&self) -> usize {
        *self
    }

    fn do_it(&self, num: usize) -> usize {
        self + num
    }
    fn add_into(&mut self, num: usize) {
        *self += num;
    }
}

#[sabi_trait]
#[doc(hidden)]
pub trait DocHiddenTrait {}

//////////////////////////////////////////

/// The trait used in examples of [`#[sabi_trait]`](macro@crate::sabi_trait)
/// trait object methods,
/// in [`abi_stable::docs::sabi_trait_inherent`]
#[abi_stable::sabi_trait]
// #[sabi(debug_print_trait)]
pub trait Action: Debug {
    /// Gets the current value of `self`.
    fn get(&self) -> usize;

    /// Adds `val` into `self`, returning the new value.
    fn add_mut(&mut self, val: usize) -> usize;

    /// Adds `val` into `self`, returning the new value.
    #[sabi(last_prefix_field)]
    fn add_into(self, val: usize) -> usize;
}

impl Action for usize {
    fn get(&self) -> usize {
        *self
    }
    fn add_mut(&mut self, val: usize) -> usize {
        *self += val;
        *self
    }
    fn add_into(mut self, val: usize) -> usize {
        self += val;
        self
    }
}