Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Derive strum's EnumIter trait for enums #197

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/image/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ pub use descriptor::*;
pub use index::*;
pub use manifest::*;
pub use oci_layout::*;
use strum_macros::EnumIter;
pub use version::*;

/// Media types used by OCI image format spec. Values MUST comply with RFC 6838,
/// including the naming requirements in its section 4.2.
#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(Clone, Debug, PartialEq, Eq, EnumIter)]
pub enum MediaType {
/// MediaType Descriptor specifies the media type for a content descriptor.
Descriptor,
Expand Down Expand Up @@ -201,7 +202,7 @@ impl<'de> Deserialize<'de> for MediaType {

/// Name of the target operating system.
#[allow(missing_docs)]
#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(Clone, Debug, PartialEq, Eq, EnumIter)]
pub enum Os {
AIX,
Android,
Expand Down Expand Up @@ -304,7 +305,7 @@ impl Default for Os {
}

/// Name of the CPU target architecture.
#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(Clone, Debug, PartialEq, Eq, EnumIter)]
pub enum Arch {
/// 32 bit x86, little-endian
#[allow(non_camel_case_types)]
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/capability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ use serde::{
};
use std::collections::HashSet;

use strum_macros::{Display, EnumString};
use strum_macros::{Display, EnumIter, EnumString};

/// Capabilities is a unique set of Capability values.
pub type Capabilities = HashSet<Capability>;

#[derive(Clone, Copy, Debug, EnumString, Eq, Display, Hash, PartialEq, Serialize)]
#[derive(Clone, Copy, Debug, EnumString, Eq, Display, Hash, PartialEq, Serialize, EnumIter)]
/// All available capabilities.
///
/// For the purpose of performing permission checks, traditional UNIX
Expand Down
28 changes: 20 additions & 8 deletions src/runtime/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use derive_builder::Builder;
use getset::{CopyGetters, Getters, MutGetters, Setters};
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, fmt::Display, path::PathBuf, vec};
use strum_macros::{Display as StrumDisplay, EnumString};
use strum_macros::{Display as StrumDisplay, EnumIter, EnumString};

#[derive(
Builder, Clone, Debug, Deserialize, Eq, Getters, MutGetters, Setters, PartialEq, Serialize,
Expand Down Expand Up @@ -187,7 +187,7 @@ pub struct LinuxIdMapping {
size: u32,
}

#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, EnumString)]
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, EnumString, EnumIter)]
#[strum(serialize_all = "lowercase")]
#[serde(rename_all = "lowercase")]
/// Device types
Expand Down Expand Up @@ -791,7 +791,9 @@ pub struct LinuxRdma {
hca_objects: Option<u32>,
}

#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, Hash, StrumDisplay)]
#[derive(
Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, Hash, StrumDisplay, EnumIter,
)]
#[strum(serialize_all = "lowercase")]
#[serde(rename_all = "snake_case")]
/// Available Linux namespaces.
Expand Down Expand Up @@ -1041,7 +1043,9 @@ pub struct LinuxSeccomp {
syscalls: Option<Vec<LinuxSyscall>>,
}

#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, StrumDisplay, EnumString)]
#[derive(
Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, StrumDisplay, EnumString, EnumIter,
)]
#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
/// Available seccomp actions.
Expand Down Expand Up @@ -1097,7 +1101,9 @@ impl Default for LinuxSeccompAction {
}

#[allow(clippy::enum_clike_unportable_variant)]
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, StrumDisplay, EnumString)]
#[derive(
Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, StrumDisplay, EnumString, EnumIter,
)]
#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
/// Available seccomp architectures.
Expand Down Expand Up @@ -1160,7 +1166,9 @@ pub enum Arch {
ScmpArchRiscv64 = 0xc00000f3,
}

#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, StrumDisplay, EnumString)]
#[derive(
Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, StrumDisplay, EnumString, EnumIter,
)]
#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
/// Available seccomp filter flags.
Expand All @@ -1185,7 +1193,9 @@ pub enum LinuxSeccompFilterFlag {
SeccompFilterFlagSpecAllow,
}

#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, StrumDisplay, EnumString)]
#[derive(
Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, StrumDisplay, EnumString, EnumIter,
)]
#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
#[repr(u32)]
Expand Down Expand Up @@ -1401,7 +1411,9 @@ pub struct LinuxPersonality {
flags: Option<Vec<String>>,
}

#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, StrumDisplay, EnumString)]
#[derive(
Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, StrumDisplay, EnumString, EnumIter,
)]
/// Define domain and flags for LinuxPersonality.
pub enum LinuxPersonalityDomain {
#[serde(rename = "LINUX")]
Expand Down
18 changes: 13 additions & 5 deletions src/runtime/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use once_cell::sync::Lazy;
use regex::Regex;
use serde::{de, Deserialize, Deserializer, Serialize};
use std::path::PathBuf;
use strum_macros::{Display as StrumDisplay, EnumString};
use strum_macros::{Display as StrumDisplay, EnumIter, EnumString};

#[derive(
Builder,
Expand Down Expand Up @@ -188,7 +188,9 @@ pub struct Box {
width: u64,
}

#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, StrumDisplay, EnumString)]
#[derive(
Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, StrumDisplay, EnumString, EnumIter,
)]
#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
#[cfg(any(target_os = "linux", target_os = "solaris"))]
Expand Down Expand Up @@ -416,7 +418,9 @@ pub struct LinuxIOPriority {
priority: i64,
}

#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, StrumDisplay, EnumString)]
#[derive(
Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, StrumDisplay, EnumString, EnumIter,
)]
#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
/// IOPriorityClass represents an I/O scheduling class.
Expand Down Expand Up @@ -505,7 +509,9 @@ impl Default for Scheduler {
}
}

#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, StrumDisplay, EnumString)]
#[derive(
Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, StrumDisplay, EnumString, EnumIter,
)]
#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
/// LinuxSchedulerPolicy represents different scheduling policies used with the Linux Scheduler
Expand Down Expand Up @@ -533,7 +539,9 @@ impl Default for LinuxSchedulerPolicy {
}
}

#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, StrumDisplay, EnumString)]
#[derive(
Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, StrumDisplay, EnumString, EnumIter,
)]
#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
/// LinuxSchedulerFlag represents the flags used by the Linux Scheduler.
Expand Down
Loading