{"id":20768831,"url":"https://github.com/1995parham-learning/rust101","last_synced_at":"2025-04-30T11:50:37.243Z","repository":{"id":91324643,"uuid":"391429431","full_name":"1995parham-learning/rust101","owner":"1995parham-learning","description":"Easy to understand applications with rust just for having fun :relieved:","archived":false,"fork":false,"pushed_at":"2024-01-06T18:50:00.000Z","size":60,"stargazers_count":11,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-01-06T19:56:06.445Z","etag":null,"topics":["learning","learning-by-doing","learning-rust","rust","rust-lang"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/1995parham-learning.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}},"created_at":"2021-07-31T18:02:38.000Z","updated_at":"2024-01-06T19:56:06.446Z","dependencies_parsed_at":"2023-12-17T11:28:07.777Z","dependency_job_id":"f7f25e1e-41e0-4444-89af-0a71865cd6c9","html_url":"https://github.com/1995parham-learning/rust101","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1995parham-learning%2Frust101","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1995parham-learning%2Frust101/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1995parham-learning%2Frust101/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1995parham-learning%2Frust101/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/1995parham-learning","download_url":"https://codeload.github.com/1995parham-learning/rust101/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225033352,"owners_count":17410435,"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","learning-by-doing","learning-rust","rust","rust-lang"],"created_at":"2024-11-17T11:41:08.846Z","updated_at":"2024-11-17T11:41:09.557Z","avatar_url":"https://github.com/1995parham-learning.png","language":"Rust","readme":"\u003cdiv align=\"center\"\u003e\n\u003ch1\u003eRust 101\u003c/h1\u003e\n\u003ch6\u003eLearning Rust with the love of your life\u003c/h6\u003e\n\u003cimg alt=\"GitHub Workflow Status (with event)\" src=\"https://img.shields.io/github/actions/workflow/status/1995parham-learning/rust101/ci.yaml?style=for-the-badge\"\u003e\n\u003c/div\u003e\n\n## Introduction\n\nEasy to understand applications with Rust just for having fun :relieved:.\n\n## Tools\n\n### rustc\n\nThe Rust compiler\n\n### cargo\n\nThe Rust dependency/project manager\n\n### Rustup\n\nRustup manages the rust versions, required programs, etc. It is a great program to simplify your rust programming workflow.\n\n## Dependencies\n\nRust handles dependencies by hand in `cargo.toml` file. In this file you specify the dependencies by their required version.\n\n```bash\n# Create a new Cargo package\ncarg new\n\n# Build and install a Rust binary\ncargo install\n\n# Compile the current package\ncargo build\n\n# Search packages in crates.io\ncargo search\n\n# Build a package's documentation\ncargo doc\n\n# Execute unit and integration tests of a package\ncargo test\n\n# Automatically fix lint warnings reported by rustc\ncargo fix\n\n# Execute benchmarks of a package\ncargo bench\n```\n\nFor finding about latest release of each cargo you can use [Docs.rs](https://docs.rs).\n\n## Expression vs Statement\n\nStatement is instruction that performs some action and do not return a value.\nExpressions evaluate to a resulting value.\n\nThe `let y = 6` statement doesn't return a value. This is different from what happens in other languages, such as C and Ruby, where the assignment returns the value of the assignment.\n\nThese are expressions:\n\n- The `6` in the statement `let y = 6;`\n- Calling a function\n- Calling a macro\n- {}\n\n## Print\n\nrust has `println!` macro which has `{}` for normal printing, `{:?}` for debug printing and `{:p}` for pointers.\n\n## Match\n\n```rust\nlet some_u8_value = Some(0u8);\nif let Some(3) = some_u8_value {\n    println!(\"three\");\n}\n\nlet some\\*u8_value = 0u8;\nmatch some_u8_value {\n    1 =\u003e println!(\"one\"),\n      2 =\u003e println!(\"two\"),\n\n      - =\u003e (),\n}\n\n# [derive(Debug)]\n\nenum UsState {\n    Alabama,\n    // --snip--\n}\n\nenum Coin {\n    Penny,\n    Nickel,\n    Dime,\n    Quarter(UsState)\n}\n\nmatch coin {\n    Coin::Penny =\u003e 1,\n    Coin::Nickel =\u003e 2,\n    Coin::Dime =\u003e 10,\n    Coin::Quarter(state) =\u003e {\n        println!(\"State quarter from {:?}!\", state);\n        25\n    },\n}\n\n```\n\n## Loops\n\n```rust\nlet result = loop {\n    counter += 1;\n    if counter == 10 {\n        break counter * 2;\n    }\n};\n```\n\n```rust\nlet a = [10, 20, 30, 40, 50];\n\nfor element in a.iter() {\n    println!(\"the value is: {}\", element)\n}\n\nfor number in (1..4).rev() {\n    println!(\"{}!\", number)\n}\n```\n\n## Stack vs. Heap\n\nAll data stored on the stack must have a known, fixed size. Data with an unknown size at compile time or a size might change must be stored on the heap instead.\nstring literals (`str` type) are stored on executable and we know them at the compile time. `String`s are stored on heap and we get their memory at the runtime from the heap.\nWe need to free heap memory and rust will do this by calling the `drop` function on that complex type.\n\n## Ownership\n\nAssignments in rust may copy or move the variable if variable has the copy trait rust will uses copy otherwise it uses move.\ntypes that doesn't have drop method in them or their parts can have copy trait otherwise there would be a compile error unless you implement the clone trait.\nWith references you can prevent moving variables.\n\n## Iterators\n\niterators have method for casting them into collections which is named /collect/.\n\n## Arrays\n\nRust arrays have fixed size and can be defined in the following ways:\n\n```rust\nlet a1 = [1, 2, 3]\nlet a2: [u64; 5] = [1, 2, 3, 4, 5]\n\n```\n\nInvalid array access doesn't cause compile error in Rust but it cause panic at runtime. Go in this case creates compile error.\n\n## Slice\n\nSlice is reference to its underlying array:\n\n```rust\n\nlet s = String::from(\"hello\")\n\nlet slice = \u0026s[..]\nlet slice = \u0026s[0..]\n\n```\n\n## Traits\n\ntraits are similar to interface in go. they can be implemented on structures or their references.\n\n## Github Actions\n\n[Unofficial GitHub Actions for Rust programming language](https://github.com/actions-rs)\n\n## To Read\n\n- [writing an os in rust](https://github.com/phil-opp/blog_os)\n\n## Crates\n\n- [clap is a simple-to-use, efficient, and full-featured library for parsing command line arguments and subcommands when writing console/terminal applications.](https://docs.rs/clap/)\n- [Serde is a framework for serializing and deserializing Rust data structures efficiently and generically.](https://serde.rs)\n- [The reqwest crate provides a convenient, higher-level HTTP Client.](https://docs.rs/reqwest)\n- [Rust client for NATS, the cloud native messaging system.](https://github.com/nats-io/nats.rs)\n- [Tokio is an asynchronous runtime for the Rust programming language.](https://tokio.rs)\n- [Termion is a pure Rust, bindless library for low-level handling, manipulating and reading information about terminals. This provides a full-featured alternative to Termbox.](https://docs.rs/termion)\n\n## Projects\n\n### Phone Book 📱\n\nPhone book application stores users and their phones as struct.\nIt has an uncomplicated menu,\nand users can add, get, and remove entities.\n\n### Word Count 🔢\n\nThis application receives a delimiter and some entries\n(i.e. some text files or array of strings) and after separation based on a delimiter,\nit will count and calculate the number of each word in the entries.\n\n### Data in Depth\n\nThis example is based on _Rust in Action_ book and shows how data is stored.\nOne of its example use rust overflow panic and\nif you build it in release mode then you don't have it.\n\n### BPF\n\nTo write BPF code in Rust, it's easiest to use cargo-bpf (part of the `redbpf` suite)\nwhich handles setting up the project and can even function as a development loader.\n\n```bash\nsudo pacman -Syu llvm\ncargo install cargo-bpf --features=llvm13\n```\n\n```bash\ncargo bpf new elbpf\ncargo bpf add hello\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F1995parham-learning%2Frust101","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F1995parham-learning%2Frust101","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F1995parham-learning%2Frust101/lists"}