Skip to content

Commit fca3950

Browse files
committed
compat: Expose From<i32> for ABI
This is useful to test Landlock outside of this crate e.g., in landlockconfig. Signed-off-by: Mickaël Salaün <mic@digikod.net>
1 parent beecdf8 commit fca3950

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/compat.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,16 @@ impl ABI {
8080
})
8181
}
8282

83-
// There is no way to not publicly expose an implementation of an external trait such as
84-
// From<i32>. See RFC https://github.com/rust-lang/rfcs/pull/2529
83+
#[cfg(test)]
84+
fn is_known(value: i32) -> bool {
85+
value > 0 && value < ABI::COUNT as i32
86+
}
87+
}
88+
89+
/// Converting from an integer to an ABI should only be used for testing.
90+
/// Indeed, manually setting the ABI can lead to inconsistent and unexpected behaviors.
91+
/// Instead, just use the appropriate access rights, this library will handle the rest.
92+
impl From<i32> for ABI {
8593
fn from(value: i32) -> ABI {
8694
match value {
8795
// The only possible error values should be EOPNOTSUPP and ENOSYS, but let's interpret
@@ -95,11 +103,6 @@ impl ABI {
95103
_ => ABI::V5,
96104
}
97105
}
98-
99-
#[cfg(test)]
100-
fn is_known(value: i32) -> bool {
101-
value > 0 && value < ABI::COUNT as i32
102-
}
103106
}
104107

105108
#[test]

0 commit comments

Comments
 (0)