aprilandjan / play-rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

play-rust

A beginner's rust-lang exploration :)

add dependencies

$ cargo add ferris-says

build & run

$ cargo build
$ cargo run

format & prettify

$ cargo fmt
$ cargo fix

Thoughts

  1. No need to write parentheses in if for control flow statement

  2. Can still use return something; if we want

  3. Seems that there's no builtin random generator, had to use crate rand to do that(ref)

  4. Seems that is is very hard to create a recursive closure?(ref)

  5. The naming conver of a .rs file in rust project is unclear, kebab-case or snake_case?(ref)

  6. Need to declare a module first before using, maybe something like #ifndef & #define in c++(ref1, ref2, ref3):

    /// define a module in some file, this in fact do the `copy file content into it` stuff work
    mod utils;
    /// use it in some other file
    use utils;
    use crate::utils;   // from 'project root directory' to find the module
    use super::utils;   // from 'parent directory' to find the module
  7. When I want to use a un-exported or indirect type from a dependency, for example, a return type from a new, it is painful. There's no such thing like typescript ReturnType<fn>, had to find where the exact typings are from, and cargo add that exact version of dep(ref1, ref2).

References

About


Languages

Language:Rust 97.4%Language:HTML 2.6%