mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
rust: Use Self wherever possible
Use Self instead of the struct name whenever possible. Automagically replace struct name with Self: `cargo clippy --fix -- -W clippy::use_self` This streamlines the code. Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com> Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com> Signed-off-by: Steffen Eiden <seiden@linux.ibm.com> Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
committed by
Jan Höppner
parent
300f8d23b5
commit
d30d272523
+14
-14
@@ -135,11 +135,11 @@ pub enum ApqnInfo {
|
||||
}
|
||||
|
||||
impl ApqnInfo {
|
||||
fn accel_info(_carddir: &str, _queuedir: &str) -> Result<ApqnInfo, String> {
|
||||
Ok(ApqnInfo::Accel(ApqnInfoAccel {}))
|
||||
fn accel_info(_carddir: &str, _queuedir: &str) -> Result<Self, String> {
|
||||
Ok(Self::Accel(ApqnInfoAccel {}))
|
||||
}
|
||||
|
||||
fn cca_info(carddir: &str, queuedir: &str) -> Result<ApqnInfo, String> {
|
||||
fn cca_info(carddir: &str, queuedir: &str) -> Result<Self, String> {
|
||||
let serialnr = match sysfs_read_string(&format!("{carddir}/serialnr")) {
|
||||
Ok(r) => r,
|
||||
Err(err) => {
|
||||
@@ -202,14 +202,14 @@ impl ApqnInfo {
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(ApqnInfo::Cca(ApqnInfoCca {
|
||||
Ok(Self::Cca(ApqnInfoCca {
|
||||
serialnr,
|
||||
mkvp_aes: aes_mkvp,
|
||||
mkvp_apka: apka_mkvp,
|
||||
}))
|
||||
}
|
||||
|
||||
fn ep11_info(carddir: &str, queuedir: &str) -> Result<ApqnInfo, String> {
|
||||
fn ep11_info(carddir: &str, queuedir: &str) -> Result<Self, String> {
|
||||
let serialnr = match sysfs_read_string(&format!("{carddir}/serialnr")) {
|
||||
Ok(r) => r,
|
||||
Err(err) => {
|
||||
@@ -250,14 +250,14 @@ impl ApqnInfo {
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(ApqnInfo::Ep11(ApqnInfoEp11 { serialnr, mkvp }))
|
||||
Ok(Self::Ep11(ApqnInfoEp11 { serialnr, mkvp }))
|
||||
}
|
||||
|
||||
fn info(mode: &ApqnMode, carddir: &str, queuedir: &str) -> Result<ApqnInfo, String> {
|
||||
fn info(mode: &ApqnMode, carddir: &str, queuedir: &str) -> Result<Self, String> {
|
||||
match mode {
|
||||
ApqnMode::Accel => ApqnInfo::accel_info(carddir, queuedir),
|
||||
ApqnMode::Cca => ApqnInfo::cca_info(carddir, queuedir),
|
||||
ApqnMode::Ep11 => ApqnInfo::ep11_info(carddir, queuedir),
|
||||
ApqnMode::Accel => Self::accel_info(carddir, queuedir),
|
||||
ApqnMode::Cca => Self::cca_info(carddir, queuedir),
|
||||
ApqnMode::Ep11 => Self::ep11_info(carddir, queuedir),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -302,8 +302,8 @@ pub struct ApqnList(Vec<Apqn>);
|
||||
|
||||
impl ApqnList {
|
||||
#[cfg(test)] // only used in test code
|
||||
pub fn from_apqn_vec(apqns: Vec<Apqn>) -> ApqnList {
|
||||
ApqnList(apqns)
|
||||
pub fn from_apqn_vec(apqns: Vec<Apqn>) -> Self {
|
||||
Self(apqns)
|
||||
}
|
||||
|
||||
#[cfg(test)] // only used in test code
|
||||
@@ -335,7 +335,7 @@ impl ApqnList {
|
||||
/// static regular expression will result in calling panic.
|
||||
/// # Panics
|
||||
/// Panics if the compilation of a static regular expression fails.
|
||||
pub fn gather_apqns() -> Option<ApqnList> {
|
||||
pub fn gather_apqns() -> Option<Self> {
|
||||
let mut apqns: Vec<Apqn> = Vec::new();
|
||||
let re_card_type = Regex::new(RE_CARD_TYPE).unwrap();
|
||||
let re_queue_dir = Regex::new(RE_QUEUE_DIR).unwrap();
|
||||
@@ -462,7 +462,7 @@ impl ApqnList {
|
||||
});
|
||||
}
|
||||
}
|
||||
Some(ApqnList(apqns))
|
||||
Some(Self(apqns))
|
||||
}
|
||||
|
||||
/// Sort this Apqnlist by card generation:
|
||||
|
||||
@@ -153,8 +153,8 @@ pub struct ApConfigList(Vec<ApConfigEntry>);
|
||||
|
||||
impl ApConfigList {
|
||||
#[cfg(test)] // only used in test code
|
||||
pub fn from_apconfigentry_vec(apconfigs: Vec<ApConfigEntry>) -> ApConfigList {
|
||||
ApConfigList(apconfigs)
|
||||
pub fn from_apconfigentry_vec(apconfigs: Vec<ApConfigEntry>) -> Self {
|
||||
Self(apconfigs)
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> Iter<'_, ApConfigEntry> {
|
||||
@@ -205,10 +205,10 @@ impl ApConfigList {
|
||||
/// Read in and validate the yaml configuration from a file.
|
||||
/// Returns a Result with Ok(ApConfigList) on success
|
||||
/// or an Err(errorstring) on failure.
|
||||
pub fn read_and_validate_yaml_file(fname: &str) -> Result<ApConfigList, String> {
|
||||
let mut apconfig = ApConfigList::read_yaml_file(fname)?;
|
||||
ApConfigList::validate(&mut apconfig)?;
|
||||
Ok(ApConfigList(apconfig))
|
||||
pub fn read_and_validate_yaml_file(fname: &str) -> Result<Self, String> {
|
||||
let mut apconfig = Self::read_yaml_file(fname)?;
|
||||
Self::validate(&mut apconfig)?;
|
||||
Ok(Self(apconfig))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -181,7 +181,7 @@ impl LockFile {
|
||||
.map_err(|err| {
|
||||
println!("Warning: could not write PID into lockfile {fname}: {err:?}.")
|
||||
});
|
||||
Ok(LockFile { lockfile })
|
||||
Ok(Self { lockfile })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user