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
//! Standard return type for invoking operations, returning success or an error
//! code.
//!
//! - Author: Philip Levis <pal@cs.stanford.edu>
//! - Date: Dec 22, 2016

/// Standard return errors in Tock.
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum ReturnCode {
    /// Success value must be positive
    SuccessWithValue { value: usize },
    /// Operation completed successfully
    SUCCESS,
    /// Generic failure condition
    FAIL,
    /// Underlying system is busy; retry
    EBUSY,
    /// The state requested is already set
    EALREADY,
    /// The component is powered down
    EOFF,
    /// Reservation required before use
    ERESERVE,
    /// An invalid parameter was passed
    EINVAL,
    /// Parameter passed was too large
    ESIZE,
    /// Operation canceled by a call
    ECANCEL,
    /// Memory required not available
    ENOMEM,
    /// Operation or command is unsupported
    ENOSUPPORT,
    /// Device does not exist
    ENODEVICE,
    /// Device is not physically installed
    EUNINSTALLED,
    /// Packet transmission not acknowledged
    ENOACK,
}

impl From<ReturnCode> for isize {
    fn from(original: ReturnCode) -> isize {
        match original {
            ReturnCode::SuccessWithValue { value } => value as isize,
            ReturnCode::SUCCESS => 0,
            ReturnCode::FAIL => -1,
            ReturnCode::EBUSY => -2,
            ReturnCode::EALREADY => -3,
            ReturnCode::EOFF => -4,
            ReturnCode::ERESERVE => -5,
            ReturnCode::EINVAL => -6,
            ReturnCode::ESIZE => -7,
            ReturnCode::ECANCEL => -8,
            ReturnCode::ENOMEM => -9,
            ReturnCode::ENOSUPPORT => -10,
            ReturnCode::ENODEVICE => -11,
            ReturnCode::EUNINSTALLED => -12,
            ReturnCode::ENOACK => -13,
        }
    }
}

impl From<ReturnCode> for usize {
    fn from(original: ReturnCode) -> usize {
        isize::from(original) as usize
    }
}