{"id":21070048,"url":"https://github.com/parthasdey2304/learning-rust","last_synced_at":"2025-03-14T02:40:55.683Z","repository":{"id":210355851,"uuid":"724971005","full_name":"parthasdey2304/learning-rust","owner":"parthasdey2304","description":"This is a repo where I am uploading all the codes of learning rust programming language","archived":false,"fork":false,"pushed_at":"2024-07-30T08:20:24.000Z","size":15,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-11T14:55:17.352Z","etag":null,"topics":[],"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/parthasdey2304.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":"2023-11-29T07:00:06.000Z","updated_at":"2024-07-30T08:20:27.000Z","dependencies_parsed_at":"2024-07-30T10:28:52.763Z","dependency_job_id":null,"html_url":"https://github.com/parthasdey2304/learning-rust","commit_stats":null,"previous_names":["parthasdey2304/learning-rust"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parthasdey2304%2Flearning-rust","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parthasdey2304%2Flearning-rust/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parthasdey2304%2Flearning-rust/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parthasdey2304%2Flearning-rust/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/parthasdey2304","download_url":"https://codeload.github.com/parthasdey2304/learning-rust/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243513344,"owners_count":20302932,"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-19T18:41:38.924Z","updated_at":"2025-03-14T02:40:55.647Z","avatar_url":"https://github.com/parthasdey2304.png","language":"Rust","readme":"\u003ch1 align=\"center\"\u003e\r\n  \u003cimg src=\"https://skillicons.dev/icons?i=rust\" alt=\"Rust Logo\" height=\"150px\" width=\"150px\"\u003e\r\n  \u003cbr\u003e\r\n \r\n\u003c/h1\u003e\r\n\r\n\u003cp\u003e\r\n   \u003cb\u003eRUST\u003c/b\u003e is a systems programming language that is focused on performance, reliability, and safety. It was designed by Mozilla and first announced in 2010. The development of Rust was largely motivated by the desire to create a language that could provide low-level control over system resources without sacrificing safety.\r\n\u003c/p\u003e\r\n\r\n# History Of Rust\r\n## Origin and Development:\r\n\r\nRust was initially a personal project of Graydon Hoare, a Mozilla employee, who started working on it in 2006.\r\nThe first public announcement of Rust was made in 2010.\r\nMozilla officially sponsored the project, and it became a part of the Mozilla Research division.\r\n\r\n## Rust 1.0 Release:\r\n\r\nRust 1.0, the first stable version, was released in May 2015.\r\nThe release marked a commitment to stability, meaning that code written in earlier versions would be compatible with future versions.\r\n\r\n## Key Features:\r\n\r\nMemory Safety: Rust's borrow checker ensures memory safety without the need for a garbage collector.\r\nConcurrency: Rust has built-in support for concurrent programming with ownership and borrowing mechanisms.\r\nZero-cost Abstractions: Rust provides high-level abstractions without incurring runtime overhead.\r\nNo Null or Dangling Pointers: Rust eliminates the possibility of null or dangling pointer references.\r\n## Community and Adoption:\r\n\r\nRust has gained popularity in both industry and open-source communities.\r\nIt is often used for systems programming, game development, and other performance-critical applications.\r\n\r\n## Tooling:\r\n\r\nRust comes with a package manager called Cargo, which makes it easy to manage dependencies and build projects.\r\nRust has a strong focus on documentation, and tools like Rustdoc generate documentation directly from the source code comments.\r\n\r\n## Ongoing Development:\r\n\r\nRust has a six-week release cycle, allowing for regular updates and improvements.\r\nThe language continues to evolve, addressing user feedback and adding new features.\r\n\r\n# Basics\r\nLet's start with a classic \"Hello, World!\" program in Rust. If you haven't installed Rust yet, you can follow the instructions on \u003ca href=\"https://www.rust-lang.org/learn/get-started\"\u003eRust's official website\u003c/a\u003e to get it set up.\r\n``` rust\r\n// This is a simple \"Hello, World!\" program in Rust.\r\nfn main() {\r\n    // The println! macro is used to print text to the console.\r\n    println!(\"Hello, World!\");\r\n}\r\n```\r\n\r\n### Explanation\r\n+ `fn main()` defines the main function. In Rust, the execution of the program starts from the main function.\r\n+ `println!` is a macro used for printing text to the console. The ! indicates that it's a macro, not a regular function.\r\n\r\n## Variables and Concept of Mutability\r\n``` rust\r\nfn main() {\r\n    // Variables are immutable by default.\r\n    let x = 5;\r\n    println!(\"The value of x is: {}\", x);\r\n\r\n    // To make a variable mutable, use the 'mut' keyword.\r\n    let mut y = 10;\r\n    println!(\"The value of y is: {}\", y);\r\n\r\n    // You can reassign a value to a mutable variable.\r\n    y = 15;\r\n    println!(\"Now, the value of y is: {}\", y);\r\n}\r\n```\r\n### Explanation\r\n+ Variables are immutable by default in Rust. Once a valie is assigned, it cannot be changed.\r\n+ The `let` keyword is used to create a variable in Rust.\r\n+ The `mut` keyword makes a variable mutable, allowing you the change its value.\r\n\r\n## Variable Shadowing\r\n+ You can shadow a variable by reusing the same variable name. This is different from mutation.\r\n``` rust\r\nfn main() {\r\n    let x = 5;\r\n    let x = x + 1; // Shadowing 'x', creates a new variable with the same name\r\n}\r\n```\r\n+ This is useful for changing the type or value of a variable while keeping the same name.\r\n\r\n## Constants\r\n+ Constants are a special kind of variable in Rust whose values cannot be changed.\r\n+ They are declared using the `const` keyword and must have a type annotation.\r\n``` rust\r\nconst PI: f32 = 3.14;\r\n```\r\n+ Constants are evaluated at compile-time and can be used in any scope, including global scope.\r\n\r\n## Data Types\r\n\r\nRust has a rich set of data types that can be categorized into a few main groups: scalar types, compound types, and user-defined types. Here's an overview of the different data types in Rust:\r\n### Scaler Types\r\n#### Integers:\r\n+ Signed Integers: `i8`, `i16`, `i32`, `i64`, `i128`\r\n+ Unsigned Integers: `u8`, `u16`, `u32`, `u64`, `u128`\r\n+ Example :\r\n``` rust\r\nlet signed_integer: i32 = -42;\r\nlet unsigned_integer: u64 = 100;\r\n```\r\n\r\n#### Floating-Point:\r\n+ Rust has two floating-point types: `f32` and `f64`\r\n+ Example :\r\n``` rust\r\nlet signed_integer: i32 = -42;\r\nlet unsigned_integer: u64 = 100;\r\n```\r\n\r\n#### Boolean:\r\n+ Represented by the `bool` ype with values `true` and `false`\r\n+ Example :\r\n``` rust\r\nlet is_rust_cool: bool = true;\r\n```\r\n\r\n#### Characters:\r\n+ Denoted by the `char` keyword and the values are written within single quotes.\r\n+ Example :\r\n``` rust\r\nlet letter: char = 'A';\r\n```\r\n\r\n### Compound Types\r\n#### Tuples:\r\n+ A fixed sized ordered list of elements of different types.\r\n+ Written with parentheses and comma-seperated values.\r\n+ Examples :\r\n``` rust\r\nlet tuple: (i32, f64, char) = (42, 3.14, 'A');\r\n```\r\n\r\n#### Arrays:\r\n+ A fixed sized array of elements of the same types.\r\n+ Written with square brackets and a specified size.\r\n+ Examples :\r\n``` rust\r\nlet array: [i32; 5] = [1, 2, 3, 4, 5];\r\n```\r\n\r\n### User-Defined Types\r\n#### Structs:\r\n+ Allow you to define your own data structures with named fields.\r\n+ Examples :\r\n``` rust\r\nstruct Person {\r\n    name: String,\r\n    age: u32,\r\n}\r\n\r\nlet person = Person {\r\n    name: String::from(\"Alice\"),\r\n    age: 30,\r\n};\r\n```\r\n\r\n#### Enums:\r\n+ Used to define a type that can have different values, each called a variant.\r\n+ Examples :\r\n``` rust\r\nenum Color {\r\n    Red,\r\n    Green,\r\n    Blue,\r\n}\r\n\r\nlet color: Color = Color::Green;\r\n```\r\n\r\n#### References:\r\n+ Allows you to refer to a value without taking the ownership of it.\r\n+ Written using the `\u0026` symbol.\r\n+ Example :\r\n``` rust\r\nlet x = 42;\r\nlet reference_to_x: \u0026i32 = \u0026x;\r\n```\r\n\r\n#### Pointers:\r\n+ Raw pointers(`const T` and `mut T`) provide more flexibility than references but come with added responsibility.\r\n+ Example :\r\n``` rust\r\nlet x = 42;\r\nlet raw_pointer: *const i32 = \u0026x;\r\n```\r\nThese are the main data types in Rust. Each type serves a specific purpose, and understanding them is crucial for effective Rust programming.\r\n\r\n## Concept of Ownership and Borrowing\r\n+ Rust's ownership system ensures memory safety by tracking ownership of variables.\r\n+ When a variable is passed to a function or assigned to another variable, ownership may be transferred or borrowed, ensuring no two parts of the code attempt to modify the same data simultaneously.\r\n+ These concepts contribute to Rust's focus on safety without sacrificing performance. Understanding ownership is particularly important as you delve into more complex programs.\r\n\r\n## Conditional Statements\r\nRust has the `if`, `else if`, and `else` constructs are used from conditional programming and branching. Here's the code snippet to demonstrate the usage:\r\n### Basic `if` Statement:\r\nThe basic `if` statement is used to execute a block of code if a condition is true:\r\n``` rust\r\nfn main() {\r\n    let number = 42;\r\n\r\n    if number \u003e 0 {\r\n        println!(\"The number is positive.\");\r\n    }\r\n}\r\n```\r\nIn this example, the `println!()` statement will be executed only if the `number` is greater than 0.\r\n\r\n### `if` with `else`:\r\nYou can use the `else` keyword to specify a block of code to be executed when the condition in the `if` statement is false:\r\n``` rust\r\nfn main() {\r\n    let number = -5;\r\n\r\n    if number \u003e 0 {\r\n        println!(\"The number is positive.\");\r\n    } else {\r\n        println!(\"The number is non-positive.\");\r\n    }\r\n}\r\n```\r\n\r\nHere, if `number` is greater than 0, the first `println!()` statement will be executed; otherwise, the `println!()` statement in the `else` block will be executed.\r\n\r\n### `if` with `else if`:\r\nYou can chain multiple conditions using `else if` to check multiple cases:\r\n``` rust\r\nfn main() {\r\n    let number = -5;\r\n\r\n    if number \u003e 0 {\r\n        println!(\"The number is positive.\");\r\n    } else {\r\n        println!(\"The number is non-positive.\");\r\n    }\r\n}\r\n```\r\n\r\nIn this example, the code checks whether `number` is positive, negative, or zero, and the appropriate block of code is executed.\r\n\r\n### Using `if` in Variable Assignments:\r\nYou can use the `if` expression for variable assignments:\r\n``` rust\r\nfn main() {\r\n    let condition = true;\r\n    let number = if condition { 42 } else { -42 };\r\n\r\n    println!(\"The number is: {}\", number);\r\n}\r\n```\r\nHere, the value assigned to `number` depends on the condition. `If` condition is true, `number` will be 42; otherwise, it will be -42.\r\n\r\nThese examples cover the basic usage of `if`, `else if`, and `else` in Rust. Understanding these constructs is fundamental for writing conditional logic in your programs.\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparthasdey2304%2Flearning-rust","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fparthasdey2304%2Flearning-rust","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparthasdey2304%2Flearning-rust/lists"}