{"id":19874936,"url":"https://github.com/adistrim/rusting","last_synced_at":"2025-03-01T01:25:20.471Z","repository":{"id":238457942,"uuid":"738834406","full_name":"adistrim/rusting","owner":"adistrim","description":"Documenting my rust learning","archived":false,"fork":false,"pushed_at":"2024-07-17T08:19:37.000Z","size":302,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-11T16:53:17.233Z","etag":null,"topics":["memory-management","mutability","ownership","rust"],"latest_commit_sha":null,"homepage":"https://adistrim.github.io/rusting/","language":"HTML","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/adistrim.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":"2024-01-04T06:40:58.000Z","updated_at":"2024-07-17T08:23:03.000Z","dependencies_parsed_at":"2024-07-17T10:15:14.593Z","dependency_job_id":"bb92abfd-77b8-489a-9541-2c39fa47aee0","html_url":"https://github.com/adistrim/rusting","commit_stats":null,"previous_names":["adistrim/rusting"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adistrim%2Frusting","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adistrim%2Frusting/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adistrim%2Frusting/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adistrim%2Frusting/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adistrim","download_url":"https://codeload.github.com/adistrim/rusting/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241302694,"owners_count":19940872,"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":["memory-management","mutability","ownership","rust"],"created_at":"2024-11-12T16:26:04.742Z","updated_at":"2025-03-01T01:25:20.449Z","avatar_url":"https://github.com/adistrim.png","language":"HTML","readme":"# Learning Rust (Basically)\n\nDocumenting my learning (Idk, maybe it can help someone else too who knows)\n\n`Rust says: I might be hard to type and compile but I will make sure you don't have to worry about memory leaks.`\n\n### Topics in this repo goes like:\n\n1. variables_and_datatypes\n2. conditionals_loops_and_functions\n3. memory_management\n4. mutability\n5. stack_and_heap\n6. ownership\n7. borrowing_and_references\n8. structs\n9. enums\n10. error_handling\n\n## Why not JavaScript (node.js) or python (fastAPI, Django)?\n\n### **1. Type Safety**:\n\nRust is statically typed, which means that the compiler can catch type errors at compile time. This is a huge advantage over dynamically typed languages like JavaScript and Python, where type errors can only be caught at runtime.\n\nSample code (JavaScript):\n\n```javascript\nlet x = 5;\nx = \"hello\";\nconsole.log(x);\n```\n\nThis code will compile and run without any errors in JavaScript, but it will throw a runtime error because we are trying to assign a string to a variable that was previously assigned a number.\n\nSample code (Python):\n\n```python\nx = 5\nx = \"hello\"\nprint(x)\n```\n\nThis code will also compile and run without any errors in Python.\n\nSample code (Rust):\n\n```rust\nfn main() {\n    let x = 5;\n    x = \"hello\";\n    println!(\"{}\", x);\n}\n```\n\nThis code will not compile in Rust because the compiler will catch the type error at compile time.\n\n`Type safety is important and that is why language like typescript was created to add type safety to JavaScript. But Rust is statically typed from the beginning, which means that type safety is built into the language from the ground up.`\n\n### **2. Memory Safety**:\n\nRust is memory safe, which means that the compiler can catch memory errors at compile time. This is a huge advantage over languages like C and C++, where memory errors can lead to security vulnerabilities and crashes.\n\nSample code (C):\n\n```c\n#include \u003cstdio.h\u003e\n\nint main() {\n    int *x = malloc(sizeof(int));\n    *x = 5;\n    free(x);\n    *x = 10;\n    printf(\"%d\\n\", *x);\n    return 0;\n}\n```\n\nThis code will compile and run without any errors in C, but it will throw a runtime error because we are trying to access memory that has already been freed.\n\nSample code (Rust):\n\n```rust\nfn main() {\n    let x = Box::new(5);\n    drop(x);\n    *x = 10;\n    println!(\"{}\", x);\n}\n```\n\nThis code will not compile in Rust because the compiler will catch the memory error at compile time.\n\n### **3. Concurrency / Multithreading**:\n\nRust has built-in support for multithreading, which makes it easy to write concurrent programs that take advantage of modern hardware.\n\n`JavaScript is single-threaded, which means that it can only run one task at a time. This can be a bottleneck for performance-critical applications that need to take advantage of multiple CPU cores. Although there're ways to run multiple threads in JavaScript, it's not as easy as in Rust.`\n\nSample code (JavaScript):\n\n```javascript\nconst start = Date.now();\n\nfunction sleep(ms) {\n  return new Promise((resolve) =\u003e setTimeout(resolve, ms));\n}\n\nasync function main() {\n  await sleep(1000);\n  console.log(\"Task 1 done\");\n  await sleep(1000);\n  console.log(\"Task 2 done\");\n  await sleep(1000);\n  console.log(\"Task 3 done\");\n  console.log(\"Total time:\", Date.now() - start);\n}\n\nmain();\n```\n\nThis code will run three tasks sequentially, each taking one second to complete. The total time taken will be around three seconds.\n\nSample code (Rust):\n\n```rust\nuse std::thread;\nuse std::time::Duration;\n\nfn main() {\n    let start = std::time::Instant::now();\n\n    let handle1 = thread::spawn(|| {\n        thread::sleep(Duration::from_secs(1));\n        println!(\"Task 1 done\");\n    });\n\n    let handle2 = thread::spawn(|| {\n        thread::sleep(Duration::from_secs(1));\n        println!(\"Task 2 done\");\n    });\n\n    let handle3 = thread::spawn(|| {\n        thread::sleep(Duration::from_secs(1));\n        println!(\"Task 3 done\");\n    });\n\n    handle1.join().unwrap();\n    handle2.join().unwrap();\n    handle3.join().unwrap();\n\n    println!(\"Total time: {:?}\", start.elapsed());\n}\n```\n\nThis code will run three tasks concurrently, each taking one second to complete. The total time taken will be around one second.\n\n### **4. Performance**:\n\nRust is a systems programming language, which means that it is designed to be fast and efficient. This makes it a great choice for performance-critical applications like game engines, operating systems, and web servers.\n\n`JavaScript and Python are high-level languages that are designed for ease of use and developer productivity, but they sacrifice performance in the process. Rust strikes a good balance between performance and productivity, making it a great choice for performance-critical applications.`\n\n### **5. Ecosystem**:\n\nRust has a growing ecosystem of libraries and tools that make it easy to build a wide range of applications. This includes web development, systems programming, game development, and more.\n\n`JavaScript and Python have large ecosystems with a wide range of libraries and tools, but they are not as well-suited for performance-critical applications. Rust's ecosystem is growing rapidly, and it is becoming a popular choice for a wide range of applications.`\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadistrim%2Frusting","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadistrim%2Frusting","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadistrim%2Frusting/lists"}