I am seeing the following errors
error[E0596]: cannot borrow data in a dereference of `tracker::TRACKER` as mutable
--> src/lib.rs:832:5
|
832 | TRACKER.initialize();
| ^^^^^^^ cannot borrow as mutable
|
= help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `tracker::TRACKER`
error[E0596]: cannot borrow data in a dereference of `tracker::TRACKER` as mutable
--> src/lib.rs:840:5
|
840 | TRACKER.file.flush().unwrap();
| ^^^^^^^^^^^^ cannot borrow as mutable
|
= help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `tracker::TRACKER`
TRACKER is defined as follows
pub struct Tracker {
pub file: fs::File
}
lazy_static! {
pub static ref TRACKER : Tracker = Tracker::new();
};
impl Tracker {
pub fn new() -> Tracker {
let file = fs::OpenOptions::new().create(true).append(true).open(WISKTRACK);
let tracker = Tracker {
file : file,
};
tracker
} else {
errorexit!("Error opening track file: {}\n", WISKTRACK.as_str());
}
}
pub fn initialize(&mut self) {
event!(Level::INFO, "Tracker Initialization:");
}
}
But if the file is changed from File to BufWriter then I see errors above.
What is the rite way to do this, without locking to access/write to the file.
I want to define a structure Tracker, with some fields, one of them is File or BuffWriter.
The Stucture Tracker will have a few methods initialize(self), writeop(self), etc.
I want to define TRACKER:Tracker as lazy_static.
and I want to be able invoke
TRACKER.initialize();
and
TRACKER.reportop("some data to be written");