• Rust >.<

    From apam@21:1/182 to All on Wed Oct 5 22:47:15 2022
    Hi

    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)

    Andrew


    --- Talisman v0.43-dev (Windows/x64)
    * Origin: Smuggler's Cove - Private BBS (21:1/182)
  • From NuSkooler@21:1/121 to apam on Wed Oct 5 11:56:19 2022

    apam around Thursday, October 6th...
    let d = fs::read_to_string("users/".to_owned() + &username + ".json")?;

    You can feed this function an actual Path object, or perhaps for the simple case just use format!()

    fs::read_to_string(format!("users/{username}.json")?;




    --
    |08 ■ |12NuSkooler |06// |12Xibalba |08- |07"|06The place of fear|07"
    |08 ■ |03xibalba|08.|03l33t|08.|03codes |08(|0344510|08/|03telnet|08, |0344511|08/|03ssh|08)
    |08 ■ |03ENiGMA 1/2 WHQ |08| |03Phenom |08| |0367 |08| |03iMPURE |08| |03ACiDic
    --- ENiGMA 1/2 v0.0.13-beta (linux; x64; 16.16.0)
    * Origin: Xibalba -+- xibalba.l33t.codes:44510 (21:1/121)
  • From tenser@21:1/101 to apam on Thu Oct 6 07:22:55 2022
    On 05 Oct 2022 at 10:47p, apam pondered and said...

    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...

    Sure!

    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")?;

    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;

    where username is a string that contains "apam"

    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?

    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)

    Cool.

    --- Mystic BBS v1.12 A47 2021/12/24 (Linux/64)
    * Origin: Agency BBS | Dunedin, New Zealand | agency.bbs.nz (21:1/101)
  • From apam@21:1/182 to NuSkooler on Thu Oct 6 10:26:11 2022
    You can feed this function an actual Path object, or perhaps for the
    simple case just use format!()

    Thanks!

    Andrew


    --- Talisman v0.43-dev (Windows/x64)
    * Origin: Smuggler's Cove - Private BBS (21:1/182)
  • From apam@21:1/182 to tenser on Thu Oct 6 10:32:09 2022
    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

    1 and 3 are the last bytes of the echo and sga telnet responses.

    so "new" didn't = "new" lol

    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.

    Andrew


    --- Talisman v0.43-dev (Windows/x64)
    * Origin: Smuggler's Cove - Private BBS (21:1/182)
  • From NuSkooler@21:1/121 to apam on Wed Oct 5 20:11:30 2022

    On Friday, October 7th apam muttered...
    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.

    An thread from just today: https://threadreaderapp.com/thread/1577667445719912450.html



    --
    |08 ■ |12NuSkooler |06// |12Xibalba |08- |07"|06The place of fear|07"
    |08 ■ |03xibalba|08.|03l33t|08.|03codes |08(|0344510|08/|03telnet|08, |0344511|08/|03ssh|08)
    |08 ■ |03ENiGMA 1/2 WHQ |08| |03Phenom |08| |0367 |08| |03iMPURE |08| |03ACiDic
    --- ENiGMA 1/2 v0.0.13-beta (linux; x64; 16.16.0)
    * Origin: Xibalba -+- xibalba.l33t.codes:44510 (21:1/121)
  • From apam@21:1/182 to NuSkooler on Thu Oct 6 16:28:17 2022
    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.

    Yes, I think the frustration stems from me doing things wrongly, and
    probably wrongly in other languages, but rust doesn't let me. I'm hoping
    the book will be a more structured way of learning than me fumbling about
    by myself.

    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.

    At present things are stored in json files (use a throw away password,
    because it's stored in plain text), but I want to try and move it over to mongodb. (Another thing I'd like to learn about)

    Oh, there is 4 nodes (threads) I have no idea what happens if they are
    filled up, also there are no time outs, time limits or concurrent login restrictions...

    Andrew


    --- Talisman v0.43-dev (Windows/x64)
    * Origin: Smuggler's Cove - Private BBS (21:1/182)
  • From tenser@21:1/101 to apam on Fri Oct 7 01:26:09 2022
    On 06 Oct 2022 at 10:32a, apam pondered and said...

    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

    That'll do it. :-) I'm not surprised that printing
    this doesn't show the 1 and 3; those are ASCII control
    characters in this context, "start-of-heading" and
    "end-of-text" and they're probably absorbed by the
    terminal. Piping the output through something like
    `cat -v` can be illuminating in these cases.

    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...

    Everyone fights the borrow checker for a little while,
    but then afterwards, it starts to make sense. I've
    been programming full-time in Rust for something like
    four years now, and I came to it really skeptical, but
    it's grown on me.

    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.

    The O'Reilly book and the one from No Starch are excellent;
    the No Starch one is the "official" book and is available
    online for free! https://doc.rust-lang.org/book/ is the
    exact same text as the dead-trees version.

    --- Mystic BBS v1.12 A47 2021/12/24 (Linux/64)
    * Origin: Agency BBS | Dunedin, New Zealand | agency.bbs.nz (21:1/101)
  • From Bugz@1:0/0 to apam on Wed Oct 12 19:39:00 2022
    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.

    Hi apam,

    The input seems -- odd? Like it isn't always detecting whether it's a
    control code or printable. If I send unicode or ctrl-b, c, d, it doesn't
    show anything, but I can backspace (and erase the prompts).

    Password input shows the control codes generate a *.

    I've been playing off and on with writing a BBS. I actually got the
    example up on the internet now.

    bbs.red-green.com 2200

    Telnet is port 2200, and SSH is port 2200. (Not a typo, both on the
    same port.)
    Supports SSH public keys for login.

    Take care,
    bugz
    (Steve)


    ... Zenmaster to hot dog vendor: "Make me one with everything."
    === MultiMail/Linux v0.52
    --- SBBSecho 3.14-Linux
    * Origin: Red-Green BBS - bbs.red-green.com (0:0/0)