diff --git a/aya-obj/src/btf/types.rs b/aya-obj/src/btf/types.rs index 177b97a5..72474f7e 100644 --- a/aya-obj/src/btf/types.rs +++ b/aya-obj/src/btf/types.rs @@ -799,9 +799,10 @@ impl DeclTag { } } -#[derive(Copy, Clone, Debug, Eq, PartialEq)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, Default)] #[repr(u32)] pub enum BtfKind { + #[default] Unknown = 0, Int = 1, Ptr = 2, @@ -879,12 +880,6 @@ impl Display for BtfKind { } } -impl Default for BtfKind { - fn default() -> Self { - BtfKind::Unknown - } -} - unsafe fn read(data: &[u8]) -> Result { if mem::size_of::() > data.len() { return Err(BtfError::InvalidTypeInfo); diff --git a/aya-obj/src/maps.rs b/aya-obj/src/maps.rs index aa2d213c..a6c3c96c 100644 --- a/aya-obj/src/maps.rs +++ b/aya-obj/src/maps.rs @@ -81,9 +81,10 @@ pub struct BtfMapDef { /// Upon pinning a map, a file representation is created for the map, /// so that the map can be alive and retrievable across sessions. #[repr(u32)] -#[derive(Copy, Clone, Debug, PartialEq, Eq)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Default)] pub enum PinningType { /// No pinning + #[default] None = 0, /// Pin by the name ByName = 1, @@ -112,12 +113,6 @@ impl TryFrom for PinningType { } } -impl Default for PinningType { - fn default() -> Self { - PinningType::None - } -} - /// Map definition in legacy BPF map declaration style #[allow(non_camel_case_types)] #[repr(C)] diff --git a/aya-obj/src/obj.rs b/aya-obj/src/obj.rs index 23943236..72f13ed7 100644 --- a/aya-obj/src/obj.rs +++ b/aya-obj/src/obj.rs @@ -1463,7 +1463,6 @@ mod tests { map_flags: 5, id: 0, pinning: PinningType::None, - ..Default::default() }; assert_eq!( @@ -1482,7 +1481,6 @@ mod tests { map_flags: 5, id: 6, pinning: PinningType::ByName, - ..Default::default() }; assert_eq!(parse_map_def("foo", bytes_of(&def)).unwrap(), def); @@ -1498,7 +1496,6 @@ mod tests { map_flags: 5, id: 6, pinning: PinningType::ByName, - ..Default::default() }; let mut buf = [0u8; 128]; unsafe { ptr::write_unaligned(buf.as_mut_ptr() as *mut _, def) }; @@ -1529,7 +1526,6 @@ mod tests { map_flags: 5, id: 0, pinning: PinningType::None, - ..Default::default() }) ), "foo" @@ -1664,7 +1660,7 @@ mod tests { buf.extend(&map_data); buf.extend(&map_data); // throw in some padding - buf.extend(&[0, 0, 0, 0]); + buf.extend([0, 0, 0, 0]); buf.extend(&map_data); assert_matches!( obj.parse_section(fake_section(BpfSectionKind::Maps, "maps", buf.as_slice(),)), @@ -2198,7 +2194,6 @@ mod tests { map_flags: BPF_F_RDONLY_PROG, id: 1, pinning: PinningType::None, - ..Default::default() }, section_index: 1, symbol_index: 1, diff --git a/aya-obj/src/programs/cgroup_sock.rs b/aya-obj/src/programs/cgroup_sock.rs index ed470f8a..b9194e24 100644 --- a/aya-obj/src/programs/cgroup_sock.rs +++ b/aya-obj/src/programs/cgroup_sock.rs @@ -7,26 +7,19 @@ use crate::{ }; /// Defines where to attach a `CgroupSock` program. -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, Default)] pub enum CgroupSockAttachType { /// Called after the IPv4 bind events. PostBind4, /// Called after the IPv6 bind events. PostBind6, /// Attach to IPv4 connect events. + #[default] SockCreate, /// Attach to IPv6 connect events. SockRelease, } -impl Default for CgroupSockAttachType { - // The kernel checks for a 0 attach_type and sets it to sock_create - // We may as well do that here also - fn default() -> Self { - CgroupSockAttachType::SockCreate - } -} - impl From for bpf_attach_type { fn from(s: CgroupSockAttachType) -> bpf_attach_type { match s {