Skip to content

watcher not available for import #393

@samuelcolvin

Description

@samuelcolvin

System details

  • OS/Platform name and version: MacOS 11.6.4
  • Rust version (if building from source): rustc --version: rustc 1.61.0-nightly (285fa7ecd 2022-03-14)
  • Notify version (or commit hash if building from git): 5.0.0-pre.14

I'm trying to use the examples from the docs for version 5.0.0-pre.14 (or any v5 version), but I'm getting the following error:

error[E0432]: unresolved import `notify::watcher`
  --> src/lib.rs:14:57
   |
14 | use notify::{RecommendedWatcher, RecursiveMode, Result, watcher};
   |                                                         ^^^^^^^
   |                                                         |
   |                                                         no `watcher` in the root
   |                                                         help: a similar name exists in the module (notice the capitalization): `Watcher`

Not entirely clear what I'm doing wrong here, the code is taken directly from the docs/examples.

This can be replicated with the example direct from the docs:

use notify::{RecommendedWatcher, RecursiveMode, Result, watcher};
use std::time::Duration;

fn main() -> Result<()> {
    // Automatically select the best implementation for your platform.
    // You can also access each implementation directly e.g. INotifyWatcher.
    let mut watcher = watcher(Duration::from_secs(2))?;

    // Add a path to be watched. All files and directories at that path and
    // below will be monitored for changes.
    watcher.watch("/home/test/notify", RecursiveMode::Recursive)?;

    // This is a simple loop, but you may want to use more complex logic here,
    // for example to handle I/O.
    for event in &watcher {
        match event {
            Ok(event) => println!("changed: {:?}", event.path),
            Err(err) => println!("watch error: {:?}", err),
        };
    }

    Ok(())
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions