Crates.io | cluFlock |
lib.rs | cluFlock |
version | 1.2.7 |
source | src |
created_at | 2018-11-11 21:34:13.016533 |
updated_at | 2022-02-15 17:41:53.656042 |
description | Installation and subsequent safe removal of `flock` locks for data streams. |
homepage | |
repository | https://github.com/clucompany/cluFlock.git |
max_upload_size | |
id | 96128 |
size | 61,472 |
Installation and subsequent safe removal of flock
locks for data streams.
use cluFlock::ToFlock;
use std::fs::File;
use std::io;
fn main() -> Result<(), io::Error> {
let file_lock = File::create("./file")?.wait_exclusive_lock()?;
println!("{:?}", file_lock);
Ok( () )
}
use std::io::Write;
use cluFlock::ToFlock;
use std::fs::File;
use std::io;
fn main() -> Result<(), io::Error> {
File::create("./file")?.wait_exclusive_lock_fn(
// valid exclusive lock
|mut file| write!(file, "Test."), // result: Ok(usize)/Err(std::io::Error)
// invalid lock
|err| Err(err.into_err()) // into_err: FlockErr -> std::io::Error
)?;
Ok(())
}
use cluFlock::ExclusiveFlock;
use std::fs::File;
fn main() -> Result<(), std::io::Error> {
let file = File::create("./file")?;
{
let file_lock = ExclusiveFlock::wait_lock(&file)?;
// file_lock, type: FlockLock<&File>
println!("{:?}", file_lock);
} // auto unlock ExclusiveFlock
file.sync_all()?;
Ok( () )
}
use std::fs::File;
use cluFlock::SharedFlock;
use std::io;
fn main() -> Result<(), io::Error> {
let file = File::create("./test_file")?;
let shared = SharedFlock::wait_lock(&file);
println!("#1shared {:?}", shared);
let shared2 = SharedFlock::try_lock(&file);
println!("#2shared {:?}", shared2);
assert_eq!(shared.is_ok(), true);
assert_eq!(shared2.is_ok(), true);
// manual or automatic unlock SharedFlock_x2
// drop(shared);
// drop(shared2);
Ok( () )
}
Copyright 2021 #UlinProject Denis Kotlyarov (Денис Котляров)
Licensed under the Apache License, Version 2.0