Coding style

This commit is contained in:
Adrian Heine 2019-03-01 18:47:47 +01:00
parent cbb5742ac3
commit abb6947853
33 changed files with 79 additions and 151 deletions

View file

@ -28,14 +28,14 @@ impl From<io::Error> for NodeJsSystemdUserServiceError<io::Error> {
impl<E: Error> Error for NodeJsSystemdUserServiceError<E> {
fn description(&self) -> &str {
match self {
&NodeJsSystemdUserServiceError::ExecError(ref e) => e.description(),
&NodeJsSystemdUserServiceError::GenericError => "Generic error",
&NodeJsSystemdUserServiceError::ActivationFailed(_) => "Activation of service failed"
NodeJsSystemdUserServiceError::ExecError(ref e) => e.description(),
NodeJsSystemdUserServiceError::GenericError => "Generic error",
NodeJsSystemdUserServiceError::ActivationFailed(_) => "Activation of service failed"
}
}
fn cause(&self) -> Option<&Error> {
match self {
&NodeJsSystemdUserServiceError::ExecError(ref e) => Some(e),
NodeJsSystemdUserServiceError::ExecError(ref e) => Some(e),
_ => None
}
}
@ -44,7 +44,7 @@ impl<E: Error> Error for NodeJsSystemdUserServiceError<E> {
impl<E: Error> fmt::Display for NodeJsSystemdUserServiceError<E> {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
try!(write!(f, "{}", self.description()));
if let &NodeJsSystemdUserServiceError::ActivationFailed(Ok(ref log)) = self {
if let NodeJsSystemdUserServiceError::ActivationFailed(Ok(ref log)) = self {
try!(write!(f, ": {:?}", log));
};
Ok(())
@ -59,10 +59,10 @@ pub struct NodeJsSystemdUserService<'a, C, R> where C: Deref<Target=str>, R: Com
}
impl<'a, R> NodeJsSystemdUserService<'a, String, SetuidCommandRunner<'a, R>> where R: CommandRunner {
pub fn new(home: &'a str, user_name: &'a str, name: &'a str, path: &'a str, command_runner: &'a R) -> Self {
let file_path = format!("{}/.config/systemd/user/{}.service", home.trim_right(), name);
pub fn new(home: &'a str, user_name: &'a str, service_name: &'a str, path: &'a str, command_runner: &'a R) -> Self {
let file_path = format!("{}/.config/systemd/user/{}.service", home.trim_right(), service_name);
let port = format!("/var/tmp/{}-{}.socket", user_name, name);
let port = format!("/var/tmp/{}-{}.socket", user_name, service_name);
let content = format!("[Service]
Environment=NODE_ENV=production
Environment=PORT={1}
@ -81,8 +81,8 @@ WantedBy=default.target
", path, port);
NodeJsSystemdUserService {
service_name: name,
user_name: user_name,
service_name,
user_name,
command_runner: SetuidCommandRunner::new(user_name, command_runner),
file: FileSymbol::new(file_path, content)
}

View file

@ -11,10 +11,7 @@ pub struct ReloadService<'a, C: 'a + CommandRunner> {
impl<'a, C: CommandRunner> ReloadService<'a, C> {
pub fn new(service: &'a str, command_runner: &'a C) -> Self {
ReloadService {
service: service,
command_runner: command_runner
}
ReloadService { service, command_runner }
}
}

View file

@ -15,13 +15,13 @@ pub enum SystemdUserSessionError<E: Error> {
impl<E: Error> Error for SystemdUserSessionError<E> {
fn description(&self) -> &str {
match self {
&SystemdUserSessionError::ExecError(ref e) => e.description(),
&SystemdUserSessionError::GenericError => "Generic error"
SystemdUserSessionError::ExecError(ref e) => e.description(),
SystemdUserSessionError::GenericError => "Generic error"
}
}
fn cause(&self) -> Option<&Error> {
match self {
&SystemdUserSessionError::ExecError(ref e) => Some(e),
SystemdUserSessionError::ExecError(ref e) => Some(e),
_ => None
}
}
@ -40,10 +40,7 @@ pub struct SystemdUserSession<'a, C: 'a + CommandRunner> {
impl<'a, C: CommandRunner> SystemdUserSession<'a, C> {
pub fn new(user_name: Cow<'a, str>, command_runner: &'a C) -> Self {
SystemdUserSession {
user_name: user_name,
command_runner: command_runner
}
SystemdUserSession { user_name, command_runner }
}
}