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
86
87
/*!
Contains the ffi-safe equivalent of `std::cmp::Ordering`.
*/


use std::cmp::Ordering;

/**
Ffi-safe equivalent of `std::cmp::Ordering`.

# Example

This defines an extern function,which compares a slice to another.

```

use abi_stable::{
    std_types::{RCmpOrdering,RSlice},
    sabi_extern_fn,
};
use std::cmp::Ord;


#[sabi_extern_fn]
pub fn compare_slices<T>(l:RSlice<'_,T>, r:RSlice<'_,T>)->RCmpOrdering
where
    T:Ord
{
    l.cmp(&r)
     .into()
}

```
*/
#[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd, Hash, Deserialize, Serialize)]
#[repr(u8)]
#[derive(StableAbi)]
pub enum RCmpOrdering {
    Less,
    Equal,
    Greater,
}

impl RCmpOrdering{
    /// Converts this `RCmpOrdering` into a `std::cmp::Ordering`;
    ///
    /// # Example
    ///
    /// ```
    /// use abi_stable::std_types::RCmpOrdering;
    /// use std::cmp::Ordering;
    /// 
    ///
    /// assert_eq!( RCmpOrdering::Less.into_ordering(), Ordering::Less );
    /// assert_eq!( RCmpOrdering::Equal.into_ordering(), Ordering::Equal );
    /// assert_eq!( RCmpOrdering::Greater.into_ordering(), Ordering::Greater );
    ///
    /// ```
    #[inline]
    pub fn into_ordering(self)->Ordering{
        self.into()
    }
}

impl_from_rust_repr! {
    impl From<Ordering> for RCmpOrdering {
        fn(this){
            match this {
                Ordering::Less=>RCmpOrdering::Less,
                Ordering::Equal=>RCmpOrdering::Equal,
                Ordering::Greater=>RCmpOrdering::Greater,
            }
        }
    }
}

impl_into_rust_repr! {
    impl Into<Ordering> for RCmpOrdering {
        fn(this){
            match this {
                RCmpOrdering::Less=>Ordering::Less,
                RCmpOrdering::Equal=>Ordering::Equal,
                RCmpOrdering::Greater=>Ordering::Greater,
            }
        }
    }
}