Unable to set permissions in RUST

Hi I have just started to program in Rust. Here is my build.rs use std::fs::{File, self}; use std::io::Write; use std::os::unix::prelude::PermissionsExt; use std::env; use std::path::{Path, PathBuf}; fn main() { let out_dir = env::var_os("CARGO_MANIFEST_DIR").unwrap(); let dest_path: PathBuf = Path::new(&out_dir).join("target/release/Settings.toml"); println!("{:?}", dest_path.as_os_str()); let f = File::create(dest_path); f.as_ref() .unwrap() .write_all("largest_number = 7".as_bytes()) .unwrap(); set_permissions(f); } fn set_permissions(f: Result<File, std::io::Error>)… Read More Unable to set permissions in RUST

static variable with BufWriter in Rust

I would like to get a global variable with BufWriter. This code is executed without errors, but writing to the file is not carried out: lazy_static! { static ref WRITER: Mutex<BufWriter<File>> = { let file = File::create("test.bin").unwrap(); BufWriter::new(file).into() } } WRITER.lock().unwrap().write_all(&vec![1, 2, 3, 4]).unwrap(); >Solution : Two things come into play: A BufWriter absorbes writes… Read More static variable with BufWriter in Rust

Write function that accepts two argument types but does the same thing

Here’s my src/main.rs file: use chrono_tz::Tz; use chrono::FixedOffset; use chrono::{NaiveDateTime, TimeZone, NaiveDate}; fn my_func(from_tz: Tz, ndt: NaiveDateTime){ let res = from_tz.from_local_datetime(&ndt); println!("res: {:?}", res); } fn main() { let area_location: Tz = "UTC".parse().unwrap(); let hour = 3600; let fixed_offset: FixedOffset = FixedOffset::east_opt(5 * hour).unwrap(); let ndt = NaiveDate::from_ymd_opt(2038, 1, 19).unwrap().and_hms_opt(3, 14, 08).unwrap(); my_func(area_location, ndt) }… Read More Write function that accepts two argument types but does the same thing