{"id":21074809,"url":"https://github.com/dawsbot/rusty-days","last_synced_at":"2026-01-01T23:05:20.081Z","repository":{"id":42023842,"uuid":"479822696","full_name":"dawsbot/rusty-days","owner":"dawsbot","description":"🎓 My journey from JavaScript to Rust","archived":false,"fork":false,"pushed_at":"2022-04-23T13:56:07.000Z","size":204,"stargazers_count":17,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-20T22:41:27.161Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Brainfuck","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dawsbot.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-04-09T19:20:08.000Z","updated_at":"2024-07-23T17:13:46.000Z","dependencies_parsed_at":"2022-08-12T02:40:28.429Z","dependency_job_id":null,"html_url":"https://github.com/dawsbot/rusty-days","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/dawsbot%2Frusty-days","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dawsbot%2Frusty-days/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dawsbot%2Frusty-days/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dawsbot%2Frusty-days/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dawsbot","download_url":"https://codeload.github.com/dawsbot/rusty-days/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243517464,"owners_count":20303632,"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":[],"created_at":"2024-11-19T19:18:10.145Z","updated_at":"2026-01-01T23:05:15.050Z","avatar_url":"https://github.com/dawsbot.png","language":"Brainfuck","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://user-images.githubusercontent.com/3408480/162672716-c9eb1afa-a317-4d01-99d2-a8db25035f44.svg\" width=\"400\"\u003e\n    \u003ch2 align=\"center\"\u003eRusty Days\u003c/h2\u003e\n\u003c/p\u003e\n\n\u003e My journey from JavaScript to Rust\n\n- I'm a web3 dev looking for higher performance.\n- Enticed that Rust was voted [**the most loved programming language**](https://insights.stackoverflow.com/survey/2021#technology-most-loved-dreaded-and-wanted)\n\nRust (aka RustLang) is a language for performance, reliability, and productivity [source](https://www.rust-lang.org/)\n\n## Resources Used:\n\n• 👑 [Rustlings](https://github.com/rust-lang/rustlings)\n\n### Cheat-Sheet\n\n- [Programming Idioms](https://www.programming-idioms.org/cheatsheet/Rust)\n\n### YouTube\n\n- [Rust Crash Course](https://www.youtube.com/watch?v=zF34dRivLOw)\n\n### Books\n\n- [Language by principles](https://doc.rust-lang.org/stable/rust-by-example)\n- [Language by examples (harder)](https://doc.rust-lang.org/book)\n\n\u003cbr/\u003e\n\u003cdetails\u003e\n  \u003csummary\u003e✅ Cool Projects using Rust\u003c/summary\u003e\n\u003cul\u003e\n  \u003cli\u003ehttps://github.com/egoist/dum\u003c/li\u003e\n  \u003cli\u003ehttps://leerob.io/blog/rust\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003e🎁 Projects I might go make one-day\u003c/summary\u003e\n\u003cul\u003e\n\u003cli\u003eRedo this in rust: https://github.com/kucherenko/jscpd\u003c/li\u003e\n\u003cli\u003eJSON get/set which has a low memory footprint through compression \u003ca href=\"https://dev.to/aero/giving-your-json-a-web-api-with-rust-290\"\u003e(could take inspiration from this)\u003c/a\u003e\u003c/li\u003e\n\n\u003c/ul\u003e\n\n\u003c/details\u003e\n\n\u003cbr/\u003e\n\u003chr/\u003e\n\n# Projects Completed\n\n- [Brainf\\*\\*k compiler](./projects/brainf)\n\n\u003cbr/\u003e\n\u003chr/\u003e\n\n# Variables\n\n- The two options are `let` and `const`\n- Unlike JavaScript, both are immutable in Rust.\n\n## `let`\n\n- The most common\n- Write as `snake_case`\n\n## `const`\n\n- Requires explicit typing at initialization `const a:char = 'a'`\n- Cannot be marked `mut`\n- Write as `SCREAMING_SNAKE_CASE`\n\n\u003cbr/\u003e\n\n# Types\n\n## Array-like\n\n\u003e If length is dynamic, you must use `vector`, otherwise arrays and tuples are more optimized\n\n### Vectors\n\n\u003e The most flexible option\n\n```rust\nlet mut v = vec![0];\nprintln!(\"element at index {} is {}\", 0, vec[0]);\n```\n\n### Arrays\n\n\u003e Fixed length at compile-time - Like Tuples except all elements must be of same type\n\n```rust\nlet a: [i32; 5] = [1, 2, 3, 4, 5];\n\n\nlet months = [\"January\", \"February\", \"March\", \"April\", \"May\", \"June\", \"July\",\n              \"August\", \"September\", \"October\", \"November\", \"December\"];\n\n// these two are the same\nlet a = [3, 3, 3, 3, 3];\nlet a = [3; 5];\n\nlet first = a[0];\nlet second = a[1];\n```\n\n### Tuples\n\n\u003e Fixed Length at compile-time - Not just two elements like some langauges do\n\n- Accessing tuple values is done with `.`\n\n```rust\nlet long_tuple = (1u8, 2u16, 3u32, 4u64,\n                      -1i8, -2i16, -3i32, -4i64,\n                      0.1f32, 0.2f64,\n                      'a', true);\n\n// Values can be extracted from the tuple using tuple indexing\nprintln!(\"long tuple first value: {}\", long_tuple.0);\nprintln!(\"long tuple second value: {}\", long_tuple.1);\n```\n\n- Long tuples cannot be printed\n\n```rust\n// long Tuples cannot be printed\n// let too_long_tuple = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13);\n// println!(\"too long tuple: {:?}\", too_long_tuple);\n// TODO ^ Uncomment the above 2 lines to see the compiler error\n```\n\n### Functions\n\n- Functions do not need to say `return`\n\n```rust\nfn reverse(pair: (i32, bool)) -\u003e (bool, i32) {\n    // `let` can be used to bind the members of a tuple to variables\n    let (integer, boolean) = pair;\n\n    (boolean, integer)\n}\n```\n\n## String like\n\n\u003e We have `char`s and two types of `string`s\n\n- Make sure you know if you're working with a [String or a Primitive String](https://youtu.be/zF34dRivLOw?t=2066)\n\n### Char\n\n\u003e Wrapped in `'`. Length 1\n\n```rust\nconst A:char = 'a';\n```\n\n### Primitive String\n\n\u003e Immutable and fixed-length\n\n```rust\nlet hello = \"hello\";\n```\n\n### String\n\n\u003e Wrapped in `\"`. Growable\n\n```rust\nlet mut hello = String::from(\"hello\");\nhello.push('W');\nhello.push_str(\"orld!\");\n```\n\n### Struct\n\n\u003e Organize complex data types. Looks kinda like a class\n\n```rust\nstruct Point {\n    x: i32,\n    y: i32,\n}\n\nfn main() {\n    let origin = Point {x: 0, y: 0};\n    println!(\"The origin is at ({}, {})\", origin.x, origin.y);\n\n    let origin2 = Point {\n        x: 99,\n        ..origin\n    };\n}\n```\n\n#### Tuple Scruct\n\n\u003e A hybrid between a struct and a tuple\n\n- Tuple structs have a name but their fields don't\n\n```rust\nstruct Color(i32, i32, i32);\nlet dark = Color(20,20,20);\n```\n\n## Errors\n\n- Many functions in rust return `Result\u003cOK_TYPE_HERE, ERR_TYPE_HERE\u003e` - This allows the dev to handle the `Ok` and the `Err` case\n\n### Non-Recoverable errors (`panic`)\n\nWant to \"throw an error\" that is **not** recoverable?\n\n```rust\npanic!(\"crash and burn\");\n```\n\n```rust\nlet v = vec![1, 2, 3];\n// index is out of range, so this will also panic\nv[99];\n```\n\n### Recoverable Errors (`Result`)\n\n- Most errors aren’t serious enough to panic. Prefer `Result` instead of `panic`\n\n- Short ways (auto-calls panic)\n\n```rust\n// does not allow for descriptive errors\nlet f = File::open(\"hello.txt\").unwrap();\n```\n\n```rust\nlet f = File::open(\"hello.txt\").expect(\"Failed to open hello.txt\");\n```\n\n- Best way (allows the parent to handle error AND is terse)\n\n```rust\nuse std::fs::File;\nuse std::io;\nuse std::io::Read;\n\nfn read_username_from_file() -\u003e Result\u003cString, io::Error\u003e {\n    // notice the \"?\"\n    let mut f = File::open(\"hello.txt\")?;\n    let mut s = String::new();\n    // notice the \"?\"\n    f.read_to_string(\u0026mut s)?;\n    Ok(s)\n}\n```\n\n- Longest way (and safest way)\n\n```rust\nuse std::fs::File;\n\nfn main() {\n    let f = File::open(\"hello.txt\");\n\n    let f = match f {\n        Ok(file) =\u003e file,\n        Err(error) =\u003e panic!(\"Problem opening the file: {:?}\", error),\n    };\n}\n```\n\n# Etc.\n\n## Semicolons mean a lot\n\n\u003e Everything in rust is either a statement or an expression\n\n- Statements do not return values\n\n```rust\nfn main() {\n    // this is a statement\n    let a = 1;\n\n    // this will error\n    // the statement `let y = 6` does not return anything\n    let x = (let y = 6);\n}\n```\n\n- This program is valid. Add a semi to `x+1` and not-so!\n\n```rust\nfn main() {\n    let y = {\n        let x = 3;\n        // notice the lack of `;`\n        // this is a valid expression\n        x + 1\n    };\n\n    println!(\"The value of y is: {}\", y);\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdawsbot%2Frusty-days","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdawsbot%2Frusty-days","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdawsbot%2Frusty-days/lists"}