mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
rust: Use AsRef<Path> and PathBuf in libraries
Use `AsRef<Path>` instead of `&Path`, &str, .... to be more versatile and accept more input types. In addition, use `PathBuf` and `Path` for paths instead of `String` and `str`. Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com> Reviewed-by: Steffen Eiden <seiden@linux.ibm.com> Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
This commit is contained in:
committed by
Steffen Eiden
parent
87d43c7a32
commit
4a76efe6d5
@@ -104,9 +104,9 @@ impl CertificateOptions {
|
||||
Ok(Box::new(NoVerifyHkd))
|
||||
}
|
||||
false => Ok(Box::new(CertVerifier::new(
|
||||
&self.certs.iter().map(Path::new).collect::<Vec<_>>(),
|
||||
&self.crls.iter().map(Path::new).collect::<Vec<_>>(),
|
||||
self.root_ca.as_ref().map(Path::new),
|
||||
&self.certs,
|
||||
&self.crls,
|
||||
self.root_ca.as_ref(),
|
||||
self.offline,
|
||||
)?)),
|
||||
}
|
||||
@@ -154,8 +154,8 @@ pub const STDOUT: &str = "-";
|
||||
pub const STDIN: &str = "-";
|
||||
|
||||
/// Converts an argument value into a Writer.
|
||||
pub fn get_writer_from_cli_file_arg(path: &str) -> Result<Box<dyn Write>> {
|
||||
if path == STDOUT {
|
||||
pub fn get_writer_from_cli_file_arg<P: AsRef<Path>>(path: P) -> Result<Box<dyn Write>> {
|
||||
if path.as_ref() == Path::new(STDOUT) {
|
||||
Ok(Box::new(std::io::stdout()))
|
||||
} else {
|
||||
Ok(Box::new(create_file(path)?))
|
||||
@@ -163,8 +163,8 @@ pub fn get_writer_from_cli_file_arg(path: &str) -> Result<Box<dyn Write>> {
|
||||
}
|
||||
|
||||
/// Converts an argument value into a Reader.
|
||||
pub fn get_reader_from_cli_file_arg(path: &str) -> Result<Box<dyn Read>> {
|
||||
if path == STDIN {
|
||||
pub fn get_reader_from_cli_file_arg<P: AsRef<Path>>(path: P) -> Result<Box<dyn Read>> {
|
||||
if path.as_ref() == Path::new(STDIN) {
|
||||
Ok(Box::new(std::io::stdin()))
|
||||
} else {
|
||||
Ok(Box::new(open_file(path)?))
|
||||
|
||||
Reference in New Issue
Block a user