diff --git a/README.md b/README.md
index b52682c..b50375d 100644
--- a/README.md
+++ b/README.md
@@ -8,16 +8,17 @@
## Example
```rust
+
extern crate parity_daemonize;
-use parity_daemonize::daemonize;
+use parity_daemonize::{AsHandle, daemonize};
use std::{thread, time, process, io};
use io::Write;
fn main() {
match daemonize("pid_file.txt") {
// we are now in the daemon, use this handle to detach from the parent process
- Ok(handle) => {
+ Ok(mut handle) => {
let mut count = 0;
loop {
// the daemon's output is piped to the parent process' stdout
@@ -35,7 +36,7 @@ fn main() {
// if this is the daemon, this is piped to the parent's stderr
eprintln!("{}", e);
// don't forget to flush
- io::stderr().flush();
+ let _ = io::stderr().flush();
process::exit(1);
}
}
diff --git a/src/error.rs b/src/error.rs
index c8b7fa0..330f38b 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -80,7 +80,7 @@ pub enum ErrorKind {
}
impl Fail for Error {
- fn cause(&self) -> Option<&Fail> {
+ fn cause(&self) -> Option<&dyn Fail> {
self.inner.cause()
}
@@ -90,7 +90,7 @@ impl Fail for Error {
}
impl Display for Error {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Display::fmt(&self.inner, f)
}
}
diff --git a/src/lib.rs b/src/lib.rs
index a766c2e..94458f3 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,4 +1,4 @@
-// Copyright 2015-2018 Parity Technologies (UK) Ltd.
+// Copyright 2015-2019 Parity Technologies (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
@@ -14,9 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see .
+//! Library for running a process as a daemon.
+//! Currently, only Linux is supported.
+
+#![warn(missing_docs, rust_2018_idioms)]
+
use crate::error::{Error, ErrorKind};
use std::path::PathBuf;
+/// Error types
pub mod error;
mod platform;
@@ -29,6 +35,7 @@ type Result = std::result::Result;
/// this can be useful, as the daemon will pipe it's stdout/stderr to the parent process
/// to communicate if start up was successful
pub trait AsHandle {
+ /// File descriptor type
type Fd;
/// Creates a `Handle` from a raw file descriptor
@@ -51,6 +58,10 @@ pub trait AsHandle {
}
#[macro_export]
+#[doc(hidden)]
+/// Macro for calling `c-style functions` and wrapping the return status in a `Result`
+/// If the function return `-1` it will return `Err<$err:expr>` otherwise `Ok(int)`
+// FIXME: this is not platform independent: `https://github.com/paritytech/parity-daemonize/issues/14`
macro_rules! map_err {
($e:expr, $err:expr) => {
match $e {
diff --git a/tests/tests.rs b/tests/tests.rs
index c1227e3..8bcd1c1 100644
--- a/tests/tests.rs
+++ b/tests/tests.rs
@@ -1,11 +1,4 @@
-use std::{
- process,
- env,
- thread,
- time,
- fs,
- io::Read
-};
+use std::{fs, io::Read, process};
#[test]
fn test_simple() {
@@ -18,7 +11,7 @@ fn test_simple() {
let mut file = fs::File::open("pid_file").unwrap();
let mut pid = String::new();
- file.read_to_string(&mut pid);
+ file.read_to_string(&mut pid).unwrap();
let _ = process::Command::new("kill")
.arg("-9")