This commit is contained in:
Adrian Heine 2019-10-08 23:31:03 +02:00
parent 64bdf403d4
commit e060ce5a68
35 changed files with 142 additions and 236 deletions

View file

@ -16,14 +16,14 @@ pub enum UserAdderError {
impl Error for UserAdderError {
fn description(&self) -> &str {
match self {
UserAdderError::AlreadyExists => "User already exists",
UserAdderError::UnknownError => "Unknown error",
UserAdderError::ImplError(_) => "User adding error",
Self::AlreadyExists => "User already exists",
Self::UnknownError => "Unknown error",
Self::ImplError(_) => "User adding error",
}
}
fn cause(&self) -> Option<&dyn Error> {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
UserAdderError::ImplError(ref e) => Some(e.as_ref()),
Self::ImplError(ref e) => Some(e.as_ref()),
_ => None,
}
}
@ -31,7 +31,7 @@ impl Error for UserAdderError {
impl fmt::Display for UserAdderError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.cause() {
match self.source() {
Some(e) => write!(f, "{} (cause: {})", self.description(), e),
None => write!(f, "{}", self.description()),
}
@ -50,10 +50,10 @@ pub enum UserError {
impl Error for UserError {
fn description(&self) -> &str {
match self {
UserError::GenericError => "Could not find out if user exists",
Self::GenericError => "Could not find out if user exists",
}
}
fn cause(&self) -> Option<&dyn Error> {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
_ => None,
}
@ -62,7 +62,7 @@ impl Error for UserError {
impl fmt::Display for UserError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.cause() {
match self.source() {
Some(e) => write!(f, "{} (cause: {})", self.description(), e),
None => write!(f, "{}", self.description()),
}
@ -136,7 +136,7 @@ impl<'a, C: CommandRunner> SystemUserAdder<'a, C> {
}
}
impl<'a, C: CommandRunner> UserAdder for SystemUserAdder<'a, C> {
impl<C: CommandRunner> UserAdder for SystemUserAdder<'_, C> {
fn add_user(&self, user_name: &str) -> Result<(), UserAdderError> {
let output = self.command_runner.run_with_args(
"adduser",
@ -152,11 +152,7 @@ impl<'a, C: CommandRunner> UserAdder for SystemUserAdder<'a, C> {
println!("{:?}", output);
Err(UserAdderError::AlreadyExists)
}
Some(_) => {
println!("{:?}", output);
Err(UserAdderError::UnknownError)
}
None => {
_ => {
println!("{:?}", output);
Err(UserAdderError::UnknownError)
}