1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//! Simple filelock library for rust, using `flock` on Unix-like systems and `LockFileEx` on Windows under the hood.
//!
//! ## Usage
//!
//! ```rust
//! fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let mut lock = filelock::new("myfile.lock");
//! let _guard = lock.lock()?;
//!
//! // Perform critical operations
//!
//! // Lock is automatically released when _guard goes out of scope
//! Ok(())
//! }
//! ```
//!
//! For manual control:
//!
//! ```rust
//! fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let mut lock = filelock::new("myfile.lock");
//! let guard = lock.lock()?;
//!
//! // Perform critical operations
//!
//! // Manually unlock with error handling
//! guard.unlock()?;
//!
//! Ok(())
//! }
//! ```
pub use FileLockGuard;
pub use FileLock;
pub use FileLock;
use Path;
/// Creates a new FileLock instance.
///
/// This is a convenience function equivalent to `FileLock::new(filename)`.
///
/// # Examples
///
/// ```rust
/// use filelock;
///
/// let mut lock = filelock::new("myfile.lock");
/// let _guard = lock.lock().unwrap();
/// ```