let d = fs::read_to_string("users/".to_owned() + &username + ".json")?;
I'm trying to learn rust.. I'm stuck however and was hoping someone more familiar with the language could tell me where I'm going wrong...
I have a json file located in "users/apam.json"
I have a function to save the userfile (that worked great) however
loading it is causing me problems...
if I load it with :
let d = fs::read_to_string("users/".to_owned() + &username + ".json")?;
where username is a string that contains "apam"
it fails with "os error, no such file or directory"
if however I do this:
let d = fs::read_to_string("users/apam.json")?;
it works...
(yes I'm practicing rust by writing a toy bbs)
You can feed this function an actual Path object, or perhaps for the
simple case just use format!()
I can't reproduce this locally, though. Copy/pasting
into `syncterm` is hard for reasons, but
I think I mentioned? I ordered a book on rust from amazon, should hopefully get here next week, in the meantime... :) Hopefully will organise my code better after working through that, at present it's a bit of a mess.
I think you'll enjoy Rust once you get moving. I've coded in many
languages over the years, but have been primarily a C++ dev for a very
long time. Ready to drop it like a bad habbit for Rust. It's the first language in a very very long time that has excited me and seems to
actually be delivering on it's promises.
I can't reproduce this locally, though. Copy/pasting
into `syncterm` is hard for reasons, but
I finally figured it out this morning, my string had some of the IAC commands in it. Strangly, printing it to the console printed like this:
String: "new"
Length: 5
then I tried iterating through the string as bytes and saw:
1
3
110
101
119
So, my error is in my read string function, and not in the file accessing at all. Thanks for the tips though! assert helped. I'm sure this code is horrible, a lot of it is me trying different things to get it to compile...
I think I mentioned? I ordered a book on rust from amazon, should hopefully get here next week, in the meantime... :) Hopefully will organise my code better after working through that, at present it's a bit of a mess.
Anyway, I got my bbs working! heh. If anyone would like to see, it's located here:
telnet scove.talismanbbs.com 8887
it's very basic, I don't intend to write another full fledged bbs like talisman or magicka, it's just a muck around for learning.
Sysop: | Gary Ailes |
---|---|
Location: | Pittsburgh, PA |
Users: | 132 |
Nodes: | 5 (0 / 5) |
Uptime: | 66:38:19 |
Calls: | 733 |
Files: | 2,171 |
Messages: | 81,303 |