Skip to content

Commit dd9326b

Browse files
d-e-s-odanielocfb
authored andcommitted
libbpf-cargo: Expose inner Rust "enum" values publicly
With the switch from emitting C enums as Rust enums to mapping them to Rust structs instead, we no longer allow access to the underlying integer. That's a bit of a usability snag, because it forces users to fall back to transmuting constants just to get a hold of the inner value. Expose the inner value publicly to make that easier. Signed-off-by: Daniel Müller <[email protected]>
1 parent 7f38370 commit dd9326b

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

libbpf-cargo/src/gen/btf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ impl<'s> GenBtf<'s> {
810810

811811
writeln!(def, r#"#[derive(Debug, Copy, Clone, Eq, PartialEq)]"#)?;
812812
writeln!(def, r#"#[repr(transparent)]"#)?;
813-
writeln!(def, r#"pub struct {enum_name}({signed}{repr_size});"#)?;
813+
writeln!(def, r#"pub struct {enum_name}(pub {signed}{repr_size});"#)?;
814814
writeln!(def, "#[allow(non_upper_case_globals)]")?;
815815
writeln!(def, r#"impl {enum_name} {{"#,)?;
816816

libbpf-cargo/src/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1880,7 +1880,7 @@ pub struct Bar {
18801880
}
18811881
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
18821882
#[repr(transparent)]
1883-
pub struct Foo(u32);
1883+
pub struct Foo(pub u32);
18841884
#[allow(non_upper_case_globals)]
18851885
impl Foo {
18861886
pub const Zero: Foo = Foo(0);
@@ -2618,7 +2618,7 @@ pub struct Foo {
26182618
}
26192619
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
26202620
#[repr(transparent)]
2621-
pub struct __anon_1(u32);
2621+
pub struct __anon_1(pub u32);
26222622
#[allow(non_upper_case_globals)]
26232623
impl __anon_1 {
26242624
pub const FOO: __anon_1 = __anon_1(1);

0 commit comments

Comments
 (0)