Skip to content

Commit

Permalink
vhost_user: Remove unnecessary method
Browse files Browse the repository at this point in the history
Since the requests implement TryFrom<u32>, the Req::is_valid() method
is no longer needed.

Signed-off-by: German Maglione <gmaglione@redhat.com>
  • Loading branch information
germag authored and stefano-garzarella committed Nov 14, 2023
1 parent 4fb2beb commit deaaecb
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions crates/vhost/src/vhost_user/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ pub const VHOST_USER_MAX_VRINGS: u64 = 0x8000u64;
pub(super) trait Req:
Clone + Copy + Debug + PartialEq + Eq + PartialOrd + Ord + Send + Sync + Into<u32> + TryFrom<u32>
{
fn is_valid(value: u32) -> bool;
}

macro_rules! enum_value {
Expand Down Expand Up @@ -182,11 +181,7 @@ enum_value! {
}
}

impl Req for FrontendReq {
fn is_valid(value: u32) -> bool {
FrontendReq::try_from(value).is_ok()
}
}
impl Req for FrontendReq {}

enum_value! {
/// Type of requests sending from backends to frontends.
Expand All @@ -213,11 +208,7 @@ enum_value! {
}
}

impl Req for BackendReq {
fn is_valid(value: u32) -> bool {
BackendReq::try_from(value).is_ok()
}
}
impl Req for BackendReq {}

/// Vhost message Validator.
pub trait VhostUserMsgValidator: ByteValued {
Expand Down Expand Up @@ -1142,18 +1133,18 @@ mod tests {

#[test]
fn check_frontend_request_code() {
let code = FrontendReq::GET_FEATURES;
assert!(FrontendReq::is_valid(code as _));
let code: u32 = FrontendReq::GET_FEATURES.into();
assert!(FrontendReq::try_from(code).is_ok());
assert_eq!(code, code.clone());
assert!(!FrontendReq::is_valid(10000));
assert!(FrontendReq::try_from(10000).is_err());
}

#[test]
fn check_backend_request_code() {
let code = BackendReq::CONFIG_CHANGE_MSG;
assert!(BackendReq::is_valid(code as _));
let code: u32 = BackendReq::CONFIG_CHANGE_MSG.into();
assert!(BackendReq::try_from(code).is_ok());
assert_eq!(code, code.clone());
assert!(!BackendReq::is_valid(10000));
assert!(BackendReq::try_from(10000).is_err());
}

#[test]
Expand Down

0 comments on commit deaaecb

Please sign in to comment.