Skip to content

Commit 2c27477

Browse files
d-e-s-odanielocfb
authored andcommitted
Remove strum_macros dependency
Remove the strum_macros dependency. Having arbitrary Display implementations for enum types makes very little sense and is generally not recommended practice. Drop the derive and just use the Debug representation where needed. Signed-off-by: Daniel Müller <[email protected]>
1 parent 2562ff9 commit 2c27477

File tree

6 files changed

+22
-57
lines changed

6 files changed

+22
-57
lines changed

Cargo.lock

Lines changed: 7 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/bpf_query/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn prog(args: ProgArgs) {
2727
let opts = query::ProgInfoQueryOptions::default().include_all();
2828
for prog in query::ProgInfoIter::with_query_opts(opts) {
2929
println!(
30-
"name={:<16} type={:<15} run_count={:<2} runtime_ns={} recursion_misses={:<2}",
30+
"name={:<16} type={:<15?} run_count={:<2} runtime_ns={} recursion_misses={:<2}",
3131
prog.name.to_string_lossy(),
3232
prog.ty,
3333
prog.run_cnt,
@@ -60,7 +60,7 @@ fn prog(args: ProgArgs) {
6060

6161
fn map() {
6262
for map in query::MapInfoIter::default() {
63-
println!("name={:<16} type={}", map.name.to_string_lossy(), map.ty);
63+
println!("name={:<16} type={:?}", map.name.to_string_lossy(), map.ty);
6464
}
6565
}
6666

libbpf-rs/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Unreleased
2+
----------
3+
- Removed `Display` implementation of various `enum` types
4+
5+
16
0.23.2
27
------
38
- Fixed build failure on Android platforms

libbpf-rs/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ vendored = ["libbpf-sys/vendored"]
2727
bitflags = "2.0"
2828
libbpf-sys = { version = "1.4.1", default-features = false }
2929
libc = "0.2"
30-
strum_macros = "0.24"
3130
vsprintf = "2.0"
3231

3332
[dev-dependencies]

libbpf-rs/src/map.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use std::slice::from_raw_parts;
2323
use bitflags::bitflags;
2424
use libbpf_sys::bpf_map_info;
2525
use libbpf_sys::bpf_obj_get_info_by_fd;
26-
use strum_macros::Display;
2726

2827
use crate::util;
2928
use crate::util::parse_ret_i32;
@@ -316,7 +315,7 @@ impl Map {
316315
pub fn attach_struct_ops(&self) -> Result<Link> {
317316
if self.map_type() != MapType::StructOps {
318317
return Err(Error::with_invalid_data(format!(
319-
"Invalid map type ({}) for attach_struct_ops()",
318+
"Invalid map type ({:?}) for attach_struct_ops()",
320319
self.map_type(),
321320
)));
322321
}
@@ -635,7 +634,7 @@ impl MapHandle {
635634
}
636635
if self.map_type().is_percpu() {
637636
return Err(Error::with_invalid_data(format!(
638-
"lookup_percpu() must be used for per-cpu maps (type of the map is {})",
637+
"lookup_percpu() must be used for per-cpu maps (type of the map is {:?})",
639638
self.map_type(),
640639
)));
641640
}
@@ -674,7 +673,7 @@ impl MapHandle {
674673
pub fn lookup_percpu(&self, key: &[u8], flags: MapFlags) -> Result<Option<Vec<Vec<u8>>>> {
675674
if !self.map_type().is_percpu() && self.map_type() != MapType::Unknown {
676675
return Err(Error::with_invalid_data(format!(
677-
"lookup() must be used for maps that are not per-cpu (type of the map is {})",
676+
"lookup() must be used for maps that are not per-cpu (type of the map is {:?})",
678677
self.map_type(),
679678
)));
680679
}
@@ -802,7 +801,7 @@ impl MapHandle {
802801
pub fn update(&self, key: &[u8], value: &[u8], flags: MapFlags) -> Result<()> {
803802
if self.map_type().is_percpu() {
804803
return Err(Error::with_invalid_data(format!(
805-
"update_percpu() must be used for per-cpu maps (type of the map is {})",
804+
"update_percpu() must be used for per-cpu maps (type of the map is {:?})",
806805
self.map_type(),
807806
)));
808807
}
@@ -881,7 +880,7 @@ impl MapHandle {
881880
pub fn update_percpu(&self, key: &[u8], values: &[Vec<u8>], flags: MapFlags) -> Result<()> {
882881
if !self.map_type().is_percpu() && self.map_type() != MapType::Unknown {
883882
return Err(Error::with_invalid_data(format!(
884-
"update() must be used for maps that are not per-cpu (type of the map is {})",
883+
"update() must be used for maps that are not per-cpu (type of the map is {:?})",
885884
self.map_type(),
886885
)));
887886
}
@@ -981,7 +980,7 @@ bitflags! {
981980
// If you add a new per-cpu map, also update `is_percpu`.
982981
#[non_exhaustive]
983982
#[repr(u32)]
984-
#[derive(Copy, Clone, PartialEq, Eq, Display, Debug)]
983+
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
985984
// TODO: Document members.
986985
#[allow(missing_docs)]
987986
pub enum MapType {

libbpf-rs/src/program.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use std::ptr::NonNull;
1414
use std::slice;
1515

1616
use libbpf_sys::bpf_func_id;
17-
use strum_macros::Display;
1817

1918
use crate::util;
2019
use crate::AsRawLibbpf;
@@ -245,7 +244,7 @@ impl AsRawLibbpf for OpenProgram {
245244
/// Type of a [`Program`]. Maps to `enum bpf_prog_type` in kernel uapi.
246245
#[non_exhaustive]
247246
#[repr(u32)]
248-
#[derive(Copy, Clone, Display, Debug)]
247+
#[derive(Copy, Clone, Debug)]
249248
// TODO: Document variants.
250249
#[allow(missing_docs)]
251250
pub enum ProgramType {
@@ -360,7 +359,7 @@ impl From<u32> for ProgramType {
360359
/// Attach type of a [`Program`]. Maps to `enum bpf_attach_type` in kernel uapi.
361360
#[non_exhaustive]
362361
#[repr(u32)]
363-
#[derive(Clone, Display, Debug)]
362+
#[derive(Clone, Debug)]
364363
// TODO: Document variants.
365364
#[allow(missing_docs)]
366365
pub enum ProgramAttachType {

0 commit comments

Comments
 (0)