Skip to main content

dope_sys/io/socket/option/
value.rs

1use std::mem;
2
3/// One socket-option value in the kernel ABI's integer domain.
4#[derive(Clone, Copy, Debug, Eq, PartialEq)]
5#[repr(transparent)]
6pub struct Value(libc::c_int);
7
8impl Value {
9    pub const ZERO: Self = Self(0);
10
11    pub const fn new(raw: i32) -> Self {
12        Self(raw)
13    }
14
15    pub const fn raw(self) -> i32 {
16        self.0
17    }
18
19    pub const fn is_zero(self) -> bool {
20        self.0 == 0
21    }
22
23    /// Encodes one boolean option as the ABI's zero/nonzero switch.
24    pub const fn from_enabled(enabled: bool) -> Self {
25        Self(enabled as libc::c_int)
26    }
27}
28
29const _: () = {
30    assert!(mem::size_of::<Value>() == mem::size_of::<i32>());
31};