Learning Rust :safe:

It takes a while to get used to and I was also still learning, but over time it changes how you code into a much safer style. With other non garbage collected languages you were left to find out much later, maybe years later and end up with insecure code that crashes occasionally and very difficult to debug and fix.

2 Likes

If you need to clone an array to copy a variable, that seems like it could be good for code security but takes extra cpu power and important array don’t become too long.

Only thing I found was this but others probably know alot more. I have spent many 50-100 hours with general dynamic arrays, global\local variables and threading in VB and Python, but my knowledge is limited in coding. So what I write may not be of use but I try until some other coding wizard comes along.

Also try youtube\ it was a life saver through college. It becomes so easy to learn when you can watch an expert show and talk about complex things.

Are you referring to structs & struct fields here? eg:

struct Foo {
    bar: String,
    some_other_data: String,
}

fn main() {
    let foo = Foo {
        bar: "bar".to_string(),
        some_other_data: "1337".to_string(),
    };

    // we take out `bar`
    let _bar = foo.bar;

    // this fails, that's because we took out `bar` and ended
    // up with an incomplete `Foo`.
    consume_foo(foo);

    // this works after commenting out the previous line. rust
    // knows that `foo.bar` is gone, but `foo.some_other_data`
    // is still there
    println!("some_other_data: {}", foo.some_other_data);
}

fn consume_foo(_foo: Foo) {}

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=3e0fb020161c59dba1b4829bc7548146

You can clone the object, but not the variable.

hmm? If a type is not clonable, then you can’t clone a struct that contains that type neither.


Or even GC langs. Rust has some other nice safety features like preventing race-conditions & safe multi-threading. Don’t event need to mention how unsafe javascript & php are…

2 Likes