#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
#[repr(i32)]
pub enum Protection
{
Inaccessible = PROT_NONE,
Read = PROT_READ,
ReadWrite = PROT_READ | PROT_WRITE,
ReadExecutable = PROT_READ | PROT_EXEC,
ReadWriteExecutable = PROT_READ | PROT_WRITE | PROT_EXEC,
}
impl Default for Protection
{
#[inline(always)]
fn default() -> Self
{
Protection::ReadWrite
}
}
impl Protection
{
#[inline(always)]
pub fn adjust_open_options_to_match(self, open_options: &mut OpenOptions) -> &mut OpenOptions
{
use self::Protection::*;
let open_options = open_options.truncate(false).append(false);
match self
{
Inaccessible => open_options,
Read | ReadExecutable => open_options.read(true),
ReadWrite | ReadWriteExecutable=> open_options.read(true).write(true),
}
}
}