Skip to content

Commit

Permalink
Improve readme, cargo metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
passcod committed Dec 20, 2014
1 parent b24a533 commit f14e83f
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 27 deletions.
19 changes: 16 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
[package]
name = "notify"
version = "1.0.0"
version = "1.0.1"
authors = ["Félix Saparelli <felix@passcod.name>"]

description = "Cross-platform filesystem notification library"
homepage = "https://github.com/passcod/rsnotify"
repository = "https://github.com/passcod/rsnotify"

readme = "README.md"
license = "CC0-1.0"
keywords = [
"events",
"filesystem",
"notify",
"watch",
]

[dependencies]
time = "*"
#inotify = "*"

[dependencies.inotify]
[target.x86_64-unknown-linux-gnu.dependencies.inotify]
git = "https://github.com/hannobraun/inotify-rs.git"
version = "0.0.1"
55 changes: 37 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,45 @@ _Cross-platform filesystem notification library for Rust._
git = "https://github.com/passcod/rsnotify.git"
```

Will be added to the [crates.io](https://crates.io) registry as soon as the
all the dependencies are published there as well.

## Usage

```rust
extern crate notify;

// Create a channel to receive the events
let (tx, rx) = channel();

// Select the recommended implementation for this platform
match notify::new(tx) {
Ok(watcher) => {
// Watch files!
watcher.watch(Path::new("/path/to/foo"));

// Receive events!
println!("{}", rx.recv());
},
Err(e) => println!("Uh oh: {}", e)
use notify::{RecommendedWatcher, Error, Watcher};

fn main() {
// Create a channel to receive the events.
let (tx, rx) = channel();

// Automatically select the best implementation for your platform.
// You can also access each implementation directly e.g. PollWatcher.
let mut w: Result<RecommendedWatcher, Error> = Watcher::new(tx);

match w {
Ok(mut watcher) => {
// Add a path to be watched. All files and directories at that path and
// below will be monitored for changes.
watcher.watch(&Path::new("/home/test/notify"));

// You'll probably want to do that in a loop. The type to match for is
// notify::Event, look at src/lib.rs for details.
match rx.recv() {
_ => println!("Recv.")
}
},
Err(e) => println!("Error")
}
}
```

## Platforms

- Linux / Android: inotify
- All platforms: polling
- All platforms: polling (only `op::WRITE`)

### Todo

Expand All @@ -42,12 +56,17 @@ match notify::new(tx) {
- BSD / OS X / iOS: kqueue
- Solaris 11: FEN

### Tests
## Known Bugs

Nothing is tested yet.
- inotify backend panics when dropped
- polling backend only handles `op::WRITE`s
- see `TODO` comments in the code for more

## Origins

Inspired by Go's [fsnotify](https://github.com/go-fsnotify/fsnotify), born out of need for [cargo watch](https://github.com/passcod/cargo-watch), and general frustration at the non-existence of C/Rust cross-platform notify libraries.
Inspired by Go's [fsnotify](https://github.com/go-fsnotify/fsnotify), born out
of need for [cargo watch](https://github.com/passcod/cargo-watch), and general
frustration at the non-existence of C/Rust cross-platform notify libraries.

Written from scratch by [Félix Saparelli](https://passcod.name), and released in the Public Domain.
Written from scratch by [Félix Saparelli](https://passcod.name), and released
in the Public Domain.
19 changes: 13 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,10 @@ pub trait Watcher {
fn unwatch(&mut self, &Path) -> Result<(), Error>;
}

#[cfg(target_os = "linux")]
pub fn new(tx: Sender<Event>) -> Result<INotifyWatcher, Error> {
Watcher::new(tx)
}
#[cfg(target_os = "linux")] pub type RecommendedWatcher = INotifyWatcher;
#[cfg(not(any(target_os = "linux")))] pub type RecommendedWatcher = PollWatcher;

#[cfg(not(any(target_os = "linux")))]
pub fn new(tx: Sender<Event>) -> Result<PollWatcher, Error> {
pub fn new(tx: Sender<Event>) -> Result<RecommendedWatcher, Error> {
Watcher::new(tx)
}

Expand All @@ -71,4 +68,14 @@ fn new_poll() {
Ok(_) => assert!(true),
Err(_) => assert!(false)
}
}

#[test]
fn new_recommended() {
let (tx, rx) = channel();
let w: Result<RecommendedWatcher, Error> = Watcher::new(tx);
match w {
Ok(_) => assert!(true),
Err(_) => assert!(false)
}
}

0 comments on commit f14e83f

Please sign in to comment.