v2/item: Implement `TryFrom<usize>` for `Kind`
// SPDX-License-Identifier: Apache-2.0
+use crate::Error;
+
+use core::convert::TryFrom;
+use libc::EINVAL;
+
#[derive(Clone, Copy, Debug, PartialEq)]
#[repr(usize)]
pub enum Kind {
@@ -8,6 +13,19 @@ pub enum Kind {
Syscall = 0x01,
}
+impl TryFrom<usize> for Kind {
+ type Error = Error;
+
+ #[inline]
+ fn try_from(kind: usize) -> Result<Self, Self::Error> {
+ match kind {
+ kind if kind == Kind::End as _ => Ok(Kind::End),
+ kind if kind == Kind::Syscall as _ => Ok(Kind::Syscall),
+ _ => Err(EINVAL),
+ }
+ }
+}
+
#[derive(Clone, Copy, Debug, PartialEq)]
#[repr(C, align(8))]
pub struct Header {
