refactor!(TpmRc): remove unnecessary Result wrapper
PATCH 1/1 refactor!(TpmRc): remove unnecessary Result wrapper
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(-)
src/data/tpm_rc.rs +7 -13
@@ -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}" ) } } }
tests/runner.rs +1 -1
@@ -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}" ); } }
Signature · 1 line
2.39.5
Quoted 5 lines · Jarkko Sakkinen
Resultwrapper in the return value ofTpmRc::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]>
This was easy test patch to check that everything is working. I'll apply it to the main branch without further ado.
Quoted 60 lines
--- src/data/tpm_rc.rs | 20 +++++++------------- tests/runner.rs | 2 +- 2 files changed, 8 insertions(+), 14 deletions(-)src/data/tpm_rc.rs +7
-13@@ -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}" ) } } }tests/runner.rs +1
-1@@ -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}" ); } }Signature · 1 line
2.39.5
BR, Jarkko