[PATCH] refactor!(TpmRc): remove unnecessary Result wrapper
Jarkko Sakkinen <[email protected]> Sun, 31 Aug 2025 12:54:44 +0300
| Newsgroups | dev.linux.lists.tpm-protocol |
|---|---|
| Message-ID | <[email protected]> |
`Result` wrapper in the return value of `TpmRc::base()` exists only to retain API backwards compatibility in 0.10.x branch. Remove the wrapper in the main branch. Signed-off-by: Jarkko Sakkinen <[email protected]> --- src/data/tpm_rc.rs | 20 +++++++------------- tests/runner.rs | 2 +- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/data/tpm_rc.rs b/src/data/tpm_rc.rs index c7fa71a..fa8756f 100644 --- a/src/data/tpm_rc.rs +++ b/src/data/tpm_rc.rs @@ -165,12 +165,9 @@ pub struct TpmRc { impl TpmRc { /// Returns the base error code, with handle, parameter, or session index /// stripped out. - /// - /// # Errors - /// - /// This method returns a `Result` in order to retain API compatibility. - pub fn base(self) -> Result<TpmRcBase, TpmErrorKind> { - Ok(self.base) + #[must_use] + pub fn base(self) -> TpmRcBase { + self.base } #[must_use] @@ -250,14 +247,11 @@ impl From<TpmRcBase> for TpmRc { impl Display for TpmRc { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - if let Ok(base) = self.base() { - if let Some(index) = self.index() { - write!(f, "[{base}, {index}]") - } else { - write!(f, "{base}") - } + let base = self.base(); + if let Some(index) = self.index() { + write!(f, "[{base}, {index}]") } else { - write!(f, "TPM_RC_UNKNOWN(0x{:08X})", self.value()) + write!(f, "{base}") } } } diff --git a/tests/runner.rs b/tests/runner.rs index 83fc209..218d813 100644 --- a/tests/runner.rs +++ b/tests/runner.rs @@ -239,7 +239,7 @@ fn test_tpm_rc_base_from_raw() { for (description, raw_rc, expected_base) in cases { let rc = TpmRc::try_from(raw_rc).unwrap(); - assert_eq!(rc.base(), Ok(expected_base), "{description}"); + assert_eq!(rc.base(), expected_base, "{description}"); } } -- 2.39.5