This is an automated email from the ASF dual-hosted git repository. ivila pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/teaclave-trustzone-sdk.git
commit 17267626a9bed2453ad51839cec6fa8f2fc4c27e Author: ivila <[email protected]> AuthorDate: Tue Jun 23 15:18:13 2026 +0800 optee-utee: use `num_enum` for conversion between ParamType and u32 Replace the hand-written conversion logic in ParamType with `num_enum::FromPrimitive`/`IntoPrimitive` derive macros. This eliminates boilerplate match statements and makes ParamType directly convertible to/from its raw u32 representation. --- crates/optee-utee/Cargo.toml | 1 + crates/optee-utee/src/parameter.rs | 34 +++++++++++----------------------- 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/crates/optee-utee/Cargo.toml b/crates/optee-utee/Cargo.toml index 51b49e5..d6b5dea 100644 --- a/crates/optee-utee/Cargo.toml +++ b/crates/optee-utee/Cargo.toml @@ -33,6 +33,7 @@ hex.workspace = true libc_alloc = "1.0.5" strum = { version = "0.28", default-features = false, features = ["derive"] } document-features.workspace = true +num_enum.workspace = true [dev-dependencies] rand.workspace = true diff --git a/crates/optee-utee/src/parameter.rs b/crates/optee-utee/src/parameter.rs index 57929c4..38708eb 100644 --- a/crates/optee-utee/src/parameter.rs +++ b/crates/optee-utee/src/parameter.rs @@ -160,28 +160,16 @@ impl From<u32> for ParamTypes { } } -#[derive(Copy, Clone)] +#[derive(Copy, Clone, num_enum::FromPrimitive, num_enum::IntoPrimitive)] +#[repr(u32)] pub enum ParamType { - None = 0, - ValueInput = 1, - ValueOutput = 2, - ValueInout = 3, - MemrefInput = 5, - MemrefOutput = 6, - MemrefInout = 7, -} - -impl From<u32> for ParamType { - fn from(value: u32) -> Self { - match value { - 0 => ParamType::None, - 1 => ParamType::ValueInput, - 2 => ParamType::ValueOutput, - 3 => ParamType::ValueInout, - 5 => ParamType::MemrefInput, - 6 => ParamType::MemrefOutput, - 7 => ParamType::MemrefInout, - _ => ParamType::None, - } - } + None = raw::TEE_PARAM_TYPE_NONE, + ValueInput = raw::TEE_PARAM_TYPE_VALUE_INPUT, + ValueOutput = raw::TEE_PARAM_TYPE_VALUE_OUTPUT, + ValueInout = raw::TEE_PARAM_TYPE_VALUE_INOUT, + MemrefInput = raw::TEE_PARAM_TYPE_MEMREF_INPUT, + MemrefOutput = raw::TEE_PARAM_TYPE_MEMREF_OUTPUT, + MemrefInout = raw::TEE_PARAM_TYPE_MEMREF_INOUT, + #[num_enum(catch_all)] + Unknown(u32), } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
