Subj : Re: Rust >.< To : apam From : tenser Date : Thu Oct 06 2022 07:22:55 On 05 Oct 2022 at 10:47p, apam pondered and said... ap> I'm trying to learn rust.. I'm stuck however and was hoping someone more ap> familiar with the language could tell me where I'm going wrong... Sure! ap> I have a json file located in "users/apam.json" ap> ap> I have a function to save the userfile (that worked great) however ap> loading it is causing me problems... ap> ap> if I load it with : ap> ap> let d = fs::read_to_string("users/".to_owned() + &username + ".json")?; So a couple of things here.... First of all, there's a Path library with PathBuf that you should use for this, instead of building up a string. Second of all, have you tried `assert!()`'ing that the file pathname you create is actually what you expect? I can't reproduce this locally, though. Copy/pasting into `syncterm` is hard for reasons, but : chandra; mkdir users : chandra; echo hi > users/apam.json : chandra; cat src/main.rs use std::fs; fn main() { let username = "apam".to_string(); let filename = "users/".to_owned() + &username + ".json"; println!("{filename}"); let d = fs::read_to_string("users/".to_owned() + &username + ".json").unwrap(); println!("{d}"); } : chandra; cargo run Finished dev [unoptimized + debuginfo] target(s) in 0.02s Running `target/debug/apam` users/apam.json hi : chandra; ap> where username is a string that contains "apam" ap> ap> it fails with "os error, no such file or directory" I think I'd try to capture the filename you think you are creating and ensure that it matches what you expect, either printing it, or in an `assert!()` (or, even better, in a `#[test]`!). Also ensure you are in the directory you think you in, since you're opening a relative path? ap> if however I do this: ap> ap> let d = fs::read_to_string("users/apam.json")?; ap> ap> it works... ap> ap> (yes I'm practicing rust by writing a toy bbs) Cool. --- Mystic BBS v1.12 A47 2021/12/24 (Linux/64) * Origin: Agency BBS | Dunedin, New Zealand | agency.bbs.nz (21:1/101) .