Hi, I'm new to Rust
I am writing a program that can log time & date into an existing log file, without replacing the old records inside but appending new records each time the program runs.
When I searched and discovered the OpenOptions can do the exact things I wanted, and took reference from few sources, so I came out like this:
use chrono::*;
use std::fs::OpenOptions;
fn log_time() -> String {
let local: DateTime<Local> = Local::now();
let date = local.format("%a, %d %b %Y %I:%M:%S %p\n").to_string();
date
}
fn log_time_into_file(filename: String) -> std::io::Result<()> {
let mut f = OpenOptions::new().append(true).create(true).open(filename);
f.write_all(log_time().as_bytes());
Ok(())
}
Upon compiling it threw error message:
error[E0599]: no method named `write_all` found for enum `std::result::Result<std::fs::File, std::io::Error>` in the current scope
Searched for the problem & solution before posting here but no avail. Looked for those tutorial references they can simply get compiled.
I may need help on this, I would like to know did I miss out something or what-else. Thanks!