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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#[allow(unused_imports)]
use core::{convert::TryFrom, fmt, mem::MaybeUninit};
#[allow(unused_imports)]
use crate::{
abi,
error::{Error, ErrorCode, ErrorKind, Kind},
};
define_error_kind! {
pub enum CurrentIdError {
#[cfg(any(feature = "fmp3", feature = "solid_fmp3"))]
BadContext,
}
}
impl ErrorKind for CurrentIdError {
fn from_error_code(code: ErrorCode) -> Option<Self> {
match code.get() {
#[cfg(any(feature = "fmp3", feature = "solid_fmp3"))]
abi::E_CTX => Some(Self::BadContext(Kind::from_error_code(code))),
_ => None,
}
}
}
#[repr(C)]
#[derive(PartialEq, Eq, Clone, Copy)]
pub struct Processor {
#[cfg(any(feature = "fmp3", feature = "solid_fmp3"))]
raw: abi::NonNullID,
_private: (),
}
impl fmt::Debug for Processor {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Processor({:?})", self.as_raw())
}
}
#[cfg(not(any(feature = "fmp3", feature = "solid_fmp3")))]
#[cfg_attr(
feature = "doc_cfg",
doc(cfg(not(any(feature = "fmp3", feature = "solid_fmp3"))))
)]
impl Processor {
pub const UNIPROCESSOR: Self = Self { _private: () };
#[cfg(not(feature = "none"))]
fn as_raw(self) {}
}
#[cfg(any(feature = "fmp3", feature = "solid_fmp3", feature = "none"))]
#[cfg_attr(
feature = "doc_cfg",
doc(cfg(any(feature = "fmp3", feature = "solid_fmp3")))
)]
impl Processor {
#[inline]
pub const fn from_raw(raw: abi::ID) -> Option<Self> {
if let Some(raw) = abi::NonNullID::new(raw) {
Some(Self::from_raw_nonnull(raw))
} else {
None
}
}
#[inline]
pub const fn from_raw_nonnull(raw: abi::NonNullID) -> Self {
match () {
#[cfg(feature = "none")]
() => {
let _ = raw;
Self::UNIPROCESSOR
}
#[cfg(not(feature = "none"))]
() => Self { raw, _private: () },
}
}
#[inline]
pub const fn as_raw(self) -> abi::ID {
self.as_raw_nonnull().get()
}
#[inline]
pub const fn as_raw_nonnull(self) -> abi::NonNullID {
match () {
#[cfg(feature = "none")]
() => unsafe { abi::NonNullID::new_unchecked(1) },
#[cfg(not(feature = "none"))]
() => self.raw,
}
}
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct ProcessorTryFromError(());
impl TryFrom<usize> for Processor {
type Error = ProcessorTryFromError;
#[cfg(not(any(feature = "fmp3", feature = "solid_fmp3")))]
#[inline]
fn try_from(x: usize) -> Result<Self, Self::Error> {
if x == 1 {
Ok(Self::UNIPROCESSOR)
} else {
Err(ProcessorTryFromError(()))
}
}
#[cfg(any(feature = "fmp3", feature = "solid_fmp3"))]
#[inline]
fn try_from(x: usize) -> Result<Self, Self::Error> {
Self::from_raw(abi::ID::try_from(x).map_err(|_| ProcessorTryFromError(()))?)
.ok_or(ProcessorTryFromError(()))
}
}
#[inline]
#[doc(alias = "get_pid")]
pub fn current() -> Result<Processor, Error<CurrentIdError>> {
match () {
#[cfg(any(feature = "fmp3", feature = "solid_fmp3"))]
() => unsafe {
let mut out = MaybeUninit::uninit();
Error::err_if_negative(abi::get_pid(out.as_mut_ptr()))?;
Ok(Processor::from_raw_nonnull(abi::NonNullID::new_unchecked(
out.assume_init(),
)))
},
#[cfg(not(any(feature = "fmp3", feature = "solid_fmp3", feature = "none")))]
() => {
Ok(Processor::UNIPROCESSOR)
}
#[cfg(feature = "none")]
() => unimplemented!(),
}
}