mirror of
https://github.com/uutils/coreutils
synced 2024-11-17 02:08:09 +00:00
uucore: {USimpleError, UUsageError}::new take Into<String> instead of String
This commit is contained in:
parent
1649217116
commit
d12d4f760c
5 changed files with 15 additions and 15 deletions
|
@ -109,7 +109,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
if derefer == 1 {
|
||||
return Err(USimpleError::new(
|
||||
1,
|
||||
"-R --dereference requires -H or -L".to_string(),
|
||||
"-R --dereference requires -H or -L",
|
||||
));
|
||||
}
|
||||
derefer = 0;
|
||||
|
|
|
@ -79,7 +79,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
print!("{}", separator);
|
||||
}
|
||||
} else {
|
||||
return Err(UUsageError::new(1, "missing operand".to_string()));
|
||||
return Err(UUsageError::new(1, "missing operand"));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -173,20 +173,20 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
if (state.nflag || state.rflag) && default_format && !state.cflag {
|
||||
return Err(USimpleError::new(
|
||||
1,
|
||||
"cannot print only names or real IDs in default format".to_string(),
|
||||
"cannot print only names or real IDs in default format",
|
||||
));
|
||||
}
|
||||
if state.zflag && default_format && !state.cflag {
|
||||
// NOTE: GNU test suite "id/zero.sh" needs this stderr output:
|
||||
return Err(USimpleError::new(
|
||||
1,
|
||||
"option --zero not permitted in default format".to_string(),
|
||||
"option --zero not permitted in default format",
|
||||
));
|
||||
}
|
||||
if state.user_specified && state.cflag {
|
||||
return Err(USimpleError::new(
|
||||
1,
|
||||
"cannot print security context when user specified".to_string(),
|
||||
"cannot print security context when user specified",
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -220,7 +220,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
} else {
|
||||
return Err(USimpleError::new(
|
||||
1,
|
||||
"--context (-Z) works only on an SELinux-enabled kernel".to_string(),
|
||||
"--context (-Z) works only on an SELinux-enabled kernel",
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1238,7 +1238,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
if separator.len() != 1 {
|
||||
return Err(UUsageError::new(
|
||||
2,
|
||||
"separator must be exactly one character long".into(),
|
||||
"separator must be exactly one character long",
|
||||
));
|
||||
}
|
||||
settings.separator = Some(separator.chars().next().unwrap())
|
||||
|
@ -1517,7 +1517,7 @@ fn exec(
|
|||
file_merger.write_all(settings, output)
|
||||
} else if settings.check {
|
||||
if files.len() > 1 {
|
||||
Err(UUsageError::new(2, "only one file allowed with -c".into()))
|
||||
Err(UUsageError::new(2, "only one file allowed with -c"))
|
||||
} else {
|
||||
check::check(files.first().unwrap(), settings)
|
||||
}
|
||||
|
|
|
@ -268,7 +268,7 @@ where
|
|||
/// let err = USimpleError { code: 1, message: "error!".into()};
|
||||
/// let res: UResult<()> = Err(err.into());
|
||||
/// // or using the `new` method:
|
||||
/// let res: UResult<()> = Err(USimpleError::new(1, "error!".into()));
|
||||
/// let res: UResult<()> = Err(USimpleError::new(1, "error!"));
|
||||
/// ```
|
||||
#[derive(Debug)]
|
||||
pub struct USimpleError {
|
||||
|
@ -278,8 +278,8 @@ pub struct USimpleError {
|
|||
|
||||
impl USimpleError {
|
||||
#[allow(clippy::new_ret_no_self)]
|
||||
pub fn new(code: i32, message: String) -> Box<dyn UError> {
|
||||
Box::new(Self { code, message })
|
||||
pub fn new<S: Into<String>>(code: i32, message: S) -> Box<dyn UError> {
|
||||
Box::new(Self { code, message: message.into() })
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -305,8 +305,8 @@ pub struct UUsageError {
|
|||
|
||||
impl UUsageError {
|
||||
#[allow(clippy::new_ret_no_self)]
|
||||
pub fn new(code: i32, message: String) -> Box<dyn UError> {
|
||||
Box::new(Self { code, message })
|
||||
pub fn new<S: Into<String>>(code: i32, message: S) -> Box<dyn UError> {
|
||||
Box::new(Self { code, message: message.into() })
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -359,9 +359,9 @@ pub struct UIoError {
|
|||
|
||||
impl UIoError {
|
||||
#[allow(clippy::new_ret_no_self)]
|
||||
pub fn new(kind: std::io::ErrorKind, context: String) -> Box<dyn UError> {
|
||||
pub fn new<S: Into<String>>(kind: std::io::ErrorKind, context: S) -> Box<dyn UError> {
|
||||
Box::new(Self {
|
||||
context,
|
||||
context: context.into(),
|
||||
inner: std::io::Error::new(kind, ""),
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue