Expand description
File system watcher service and other types.
The WATCHER service can be used to get notifications when a file or directory is modified. It also provides
ways to bind a file to a variable, automatically synchronizing both.
The example below binds the current content of a text file to at text variable using WATCHER.read.
Any external change made to the text file updates the UI text.
use zng::{fs_watcher::WATCHER, prelude::*};
Text!(WATCHER.read("dump.log", Txt::from(""), |f| f.ok()?.text().ok()))The next example created a read-write binding with the text file, any external change made to the text file updates the
TextInput! and any change made using the TextInput! updates the file contents.
use zng::{fs_watcher::WATCHER, prelude::*};
TextInput!(zng::fs_watcher::WATCHER.sync(
"dump.log",
// initial value
Txt::from(""),
// read, only updates txt if returns Some
|f| f.ok()?.text().ok(),
// write, only change file if commit called.
|txt, f| {
if let Ok(mut f) = f {
if f.write_text(&txt).is_ok() {
// replace actual file with temp that was successfully written.
let _ = f.commit();
} else {
f.cancel();
}
}
},
))The WATCHER service abstracts away most of the headache of interacting with the file system. This service
is used internally by the implementations of CONFIG and L10N.
§Full API
See zng_ext_fs_watcher for the full watcher API.
Modules§
- fs_
event - File system change event types.
Structs§
- FsChange
- Represents a single file system change, annotated.
- FsChange
Note Handle - Handle that holds a
WATCHER.annotatenote. - FsChanges
Args FS_CHANGES_EVENTarguments.- WATCHER
- File system watcher service.
- Watch
File - Represents an open read-only file provided by
WATCHER.read. - Watcher
Handle - Represents an active file or directory watcher in
WATCHER. - Write
File - Represents an open write file provided by
WATCHER.sync.
Statics§
- FS_
CHANGES_ EVENT - Event sent by the
WATCHERservice on directories or files that are watched.
Traits§
- FsChange
Note - Represents a
FsChangenote. - IMAGES_
Ext - File watcher extensions for
IMAGESservice. - Watcher
Read Status - Represents a status type for
WATCHERread-only operations. - Watcher
Sync Status - Represents a status type for
WATCHER.sync_status.