{"id":23353690,"url":"https://github.com/daniqss/learning_rust","last_synced_at":"2025-04-07T19:20:00.215Z","repository":{"id":203173346,"uuid":"708995313","full_name":"daniqss/learning_rust","owner":"daniqss","description":"Basic exercicies to learn Rust programming language","archived":false,"fork":false,"pushed_at":"2024-11-30T23:26:20.000Z","size":3014,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-13T20:49:16.915Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/daniqss.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-23T19:58:04.000Z","updated_at":"2024-11-30T23:26:24.000Z","dependencies_parsed_at":"2023-11-13T12:30:33.410Z","dependency_job_id":"6fa966f0-e2ab-4658-879e-14e2f4596e07","html_url":"https://github.com/daniqss/learning_rust","commit_stats":null,"previous_names":["ranicocs/learning_rust","daniqss/learning_rust"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniqss%2Flearning_rust","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniqss%2Flearning_rust/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniqss%2Flearning_rust/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniqss%2Flearning_rust/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daniqss","download_url":"https://codeload.github.com/daniqss/learning_rust/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247713263,"owners_count":20983683,"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-12-21T09:15:21.095Z","updated_at":"2025-04-07T19:20:00.178Z","avatar_url":"https://github.com/daniqss.png","language":"Rust","readme":"# Learning Rust\n\nLittle programs to learn the basic concepts of the Rust programming language\n\n## Useful sites\n* https://doc.rust-lang.org/stable/book/\n* https://tourofrust.com/TOC_en.html\n* https://doc.rust-lang.org/rust-by-example/\n* https://midu.dev/rust-para-desarrolladores-javascript/\n\n## Specific information\n* [Ownership](ownership/Ownership.md)\n* [Concurrency](concurrency-and-ffi/Concurrency.md)\n\n## Compilation\n\nWith `cargo init`  we create a proyect in which we can use `cargo run` to compile and run our program. The binaty is saved in `target/debug/\u003cfile_name\u003e`.\n\nTo compile just one file we can use:\n```bash\nrustc \u003cnombre_del_fichero\u003e.rs\n```\n\n## Variables\n\nVariables are declared using the **let** keyword\nTypes are infered by the compiler but they can be added to the variable declaration\nVariables are inmutable by default. **mut** keyword can be used to make a variable mutable\n\n```rust\nfn main () {\n\tlet x = 69;\n\tlet y: f64 = 2.71;\n\tlet mut z: i64 = 434243234545;\n}\n```\n\nIn Rust, variable names are written in **snake_case**\n\n### Types\n* bool -\u003e true, false\n* unsigned integer -\u003e u8, u16, u32, u64, u128\n* signed integer -\u003e i8, i16, i32, i64, i128\n* floating -\u003e f32, f64\n\n\n### Arrays\n\nFixed lenght collection of elements all of the same type. C indexation style.\n\n```rust\nfn main() {\n    let nums: [i32; 3] = [1, 2, 3];\n    println!(\"{:?}\", nums);\n    println!(\"{}\", nums[1]);\n}\n```\n\n```bash\n[1, 2, 3]\n2\n```\n\nTo make dynamic arrays use Vectors\n\n## Functions\n\nAlways in snake_case. If you just want to return an expression, you can drop the `return` keyword and the semicolon at the end, as we did in the _subtract_ function.\n\n```rust\nfn add(x: i32, y: i32) -\u003e i32 {\n    return x + y;\n}\n\nfn subtract(x: i32, y: i32) -\u003e i32 {\n    x - y\n}\n\nfn main() {\n    println!(\"42 + 13 = {}\", add(42, 13));\n    println!(\"42 - 13 = {}\", subtract(42, 13));\n}\n```\n\nIf no return type is specified for a function, it returns an empty tuple, also known as a _unit_ like in ocaml.\nAn empty tuple is represented by `()`.\n## Tuples\n\nTuple elements can be referenced by their index number. (like c structs)\n\n```rust\nfn swap(x: i32, y: i32) -\u003e (i32, i32) {\n    return (y, x);\n}\n\nfn main() {\n    // return a tuple of return values\n    let result = swap(123, 321);\n    println!(\"{} {}\", result.0, result.1);\n\n    // destructure the tuple into two variables names\n    let (a, b) = swap(result.0, result.1);\n    println!(\"{} {}\", a, b);\n}\n\n```\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaniqss%2Flearning_rust","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaniqss%2Flearning_rust","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaniqss%2Flearning_rust/lists"}