{"id":22221113,"url":"https://github.com/davesag/rust-tutorial","last_synced_at":"2025-03-25T07:42:24.912Z","repository":{"id":138279762,"uuid":"130536031","full_name":"davesag/rust-tutorial","owner":"davesag","description":"Just me learning Rust by doing the tutorial exercises.","archived":false,"fork":false,"pushed_at":"2018-04-22T09:14:27.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"develop","last_synced_at":"2025-01-30T07:13:34.636Z","etag":null,"topics":["learning-by-doing","learning-rust","rust","tutorial-exercises"],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/davesag.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-04-22T04:46:42.000Z","updated_at":"2023-04-11T15:22:56.000Z","dependencies_parsed_at":null,"dependency_job_id":"2911121b-58f7-4dd0-b7b1-6e8d9581fb59","html_url":"https://github.com/davesag/rust-tutorial","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davesag%2Frust-tutorial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davesag%2Frust-tutorial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davesag%2Frust-tutorial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davesag%2Frust-tutorial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davesag","download_url":"https://codeload.github.com/davesag/rust-tutorial/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245422921,"owners_count":20612725,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["learning-by-doing","learning-rust","rust","tutorial-exercises"],"created_at":"2024-12-02T23:12:18.749Z","updated_at":"2025-03-25T07:42:24.891Z","avatar_url":"https://github.com/davesag.png","language":"Rust","readme":"# rust-tutorial\n\nJust me [learning Rust](https://doc.rust-lang.org) by doing the tutorial exercises.\n\n* `develop` [![CircleCI](https://circleci.com/gh/davesag/rust-tutorial/tree/develop.svg?style=svg)](https://circleci.com/gh/davesag/rust-tutorial/tree/develop)\n* `master` [![CircleCI](https://circleci.com/gh/davesag/rust-tutorial/tree/master.svg?style=svg)](https://circleci.com/gh/davesag/rust-tutorial/tree/master)\n\n## Getting started with Rust on macOS (with Homebrew)\n\n### Install stuff\n\n    brew install rustup\n    rustup-init\n\nUse the defaults then, once that's done also do\n\n    rustup completions bash \u003e $(brew --prefix)/etc/bash_completion.d/rustup.bash-completion\n    source $HOME/.cargo/env\n\ncheck it all worked with\n\n    rustc --version\n\nYou should get something like\n\n    ~$ rustc 1.25.0 (84203cac6 2018-03-25)\n\nNow install `cargo-edit`\n\n    cargo install cargo-edit\n\nLet that complete.\n\nNow you can add dependencies to your project using\n\n    cargo add \u003csome-library\u003e\n\ninstead of having to look up the speccific library version and manually edit the `Cargo.toml` file.\n\nThen add `rustfmt-preview` to your toolchain.\n\n    rustup component add rustfmt-preview\n\nNow you can run the rust code formatter (aka linting)\n\n### Keep it up to date\n\n    rustup update\n\n### Handy `cargo` commands\n\nCreate a new application project\n\n    cargo new \u003cproject_name\u003e\n\nCreate a new library project\n\n    cargo new \u003cproject_name\u003e --lib\n\nGenerate project documentation (including for dependencies) and open the docs in your browser\n\n    cargo doc --open\n\nBuild a project\n\n    cargo build\n\nRun the debug version of the built project\n\n    cargo run\n\nBuild and run the release version of the project\n\n    cargo build --release\n    cargo run --release\n\nRun tests (when there are tests to run)\n\n    cargo test\n\nLinting\n\n    cargo fmt -- --write-mode=diff\n\n### Things to note\n\n### Strings\n\n* A `String` is just a vector of 8-byte chars\n* String constants can't be passed in to macros.\n\n  so you can't do\n\n      println!(SOME_STRING_CONSTANT)\n\n  but you can do\n\n      fn printer(msg: \u0026str) { println!(\"{}\", msg); }\n      printer(\u0026SOME_STRING_CONSTANT);\n\n  but functions can't have default or optional params (that I can work out anyway)\n\n  You _can't_ do something like\n\n      fn printer(msgFmt: \u0026str, val: u32) { println!(\u0026msgFmt, val); }\n\n### Integers\n\nLength | Signed | Unsigned\n-------|--------|---------\n8-bit  | i8     | u8\n16-bit | i16    | u16\n32-bit | i32    | u32\n64-bit | i64    | u64\narch   | isize  | usize\n\n### Floats\n\n`f32` and `f64`. `f64` is the default.\n\n### Tuples\n\n    let tup: (i32, f64, u8) = (500, 6.4, 1);\n    // with destructuring\n    let (x, y, z) = tup;\n    // or via dot notation\n    let n = tup.0; // gives 500\n\n### Arrays\n\nArrays are fixed. If you need to add or remove items from a list use a `vector`.\n\n    let a = [1, 2, 3, 4, 5];\n    let one = a[0];\n\n#### `let` vs `const` and the use of `mut`\n\nConstants must have a type.\n\n    const A_NUMBER: u32 = 153;\n    const A_CONSTANT: \u0026str = \"This can't be changed or shadowed.\";\n\nVariables are immutable by default\n\n    let my_string = \"this can't be changed directly\";\n\nbut can be shadowed\n\n    let my_string = \"but it can be shadowed via use of another let\"\n    let my_string = my_string.len() // including being shadowed by a new type.\n\nVariables can use `mut` to declare them as mutable.\n\n    let mut my change_me = \"this can be changed\"\n    change_me = \"but not to a new type\"\n\n### Expressions and statements\n\nIf you add a semicolon to the end of an expression, you turn it into a statement, which will then not return a value.\n\nSo\n\n    {\n      let x = 3;\n      x + 1\n    }\n\nis an expression that evaluates to `4`\n\n### Return values from functions\n\n    fn five() -\u003e i32 {\n        5\n    }\n\n    let x = five();\n\n    fn add_one(n: i32) -\u003e i32 {\n        n + 1\n    }\n\n    let y = add_one(x);\n\n### `if` .. `else` can be assigned\n\n    fn some_test(is_it: bool) -\u003e i32 {\n      if is_it {\n        1\n      } else }\n        0\n      }\n    }\n\n    let x = is_it(true) // 1\n    let y = is_it(false) // 0\n\n### History and other info\n\n* Rust was originally developed by [Graydon Hoare](https://twitter.com/graydon_pub) who now wroks at Apple on the Swift language.\n* [Graydon is a biology nerd](https://www.reddit.com/r/rust/comments/27jvdt/internet_archaeology_the_definitive_endall_source/).\n* Rust is named after [a fungus](https://en.wikipedia.org/wiki/Rust_%28fungus%29) that is robust, distributed, and parallel.\n* A Rust developer is known as a 'Rustacean' (rhymes with crustacean)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavesag%2Frust-tutorial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavesag%2Frust-tutorial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavesag%2Frust-tutorial/lists"}