{"id":25932436,"url":"https://github.com/yomnaali22/rust_simple_programs","last_synced_at":"2025-09-10T15:39:33.947Z","repository":{"id":279272023,"uuid":"938253929","full_name":"Yomnaali22/rust_simple_programs","owner":"Yomnaali22","description":"Rise in task: basic programs that uses ownership concepts, enums, structs and error handling","archived":false,"fork":false,"pushed_at":"2025-03-16T16:48:36.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-13T02:26:44.070Z","etag":null,"topics":["enums","impl","input","ownership","rust","struct"],"latest_commit_sha":null,"homepage":"","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/Yomnaali22.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":"2025-02-24T16:58:58.000Z","updated_at":"2025-02-26T18:05:55.000Z","dependencies_parsed_at":"2025-03-16T23:16:32.879Z","dependency_job_id":null,"html_url":"https://github.com/Yomnaali22/rust_simple_programs","commit_stats":null,"previous_names":["yomnaali22/rust_simple_program","yomnaali22/rust_simple_programs"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Yomnaali22/rust_simple_programs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yomnaali22%2Frust_simple_programs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yomnaali22%2Frust_simple_programs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yomnaali22%2Frust_simple_programs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yomnaali22%2Frust_simple_programs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Yomnaali22","download_url":"https://codeload.github.com/Yomnaali22/rust_simple_programs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yomnaali22%2Frust_simple_programs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274483266,"owners_count":25293812,"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","status":"online","status_checked_at":"2025-09-10T02:00:12.551Z","response_time":83,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["enums","impl","input","ownership","rust","struct"],"created_at":"2025-03-04T00:37:37.920Z","updated_at":"2025-09-10T15:39:33.580Z","avatar_url":"https://github.com/Yomnaali22.png","language":"Rust","readme":"# 📌 Rust String Concatenation: Ownership \u0026 Borrowing\n\n## 📖 Task Details\nIn this task, students will create a simple Rust program that demonstrates the concepts of **ownership, borrowing, and references**. The program will take two strings as input, concatenate them, and then print the result **without violating any ownership rules**.\n\n---\n\n## 🚀 Program Code\n```rust\nfn concatenate_strings(str1: \u0026str, str2: \u0026str) -\u003e String {\n    let mut result = String::new(); // mutable variable\n    result.push_str(str1);\n    result.push_str(str2);\n    return result;\n}\n\nfn main() {\n    let string1: String = String::from(\"hello\");\n    let string2: String = String::from(\" world\");\n    let concatenated_string = concatenate_strings(\u0026string1, \u0026string2); // \u0026 for borrowing \n    println!(\"{}\", concatenated_string);\n}\n```\n\n---\n\n## 📝 Explanation\n- The function **`concatenate_strings`** takes two **borrowed** string slices (`\u0026str`).\n- This prevents **ownership transfer**, allowing `string1` and `string2` to still be used after the function call.\n- A **new `String`** is created inside the function, modified with `push_str()`, and returned.\n- In `main()`, the function is called using **borrowed references** (`\u0026string1` and `\u0026string2`).\n- This ensures **no ownership violations** while efficiently concatenating the strings.\n\n---\n\n## ✅ Expected Output\n```\nhello world\n```\n\n---\n\n## 📌 Key Concepts Demonstrated\n- **Ownership**: The function does not take ownership of `string1` and `string2`, allowing them to be reused.\n- **Borrowing \u0026 References**: The function parameters use `\u0026str`, enabling safe and efficient string handling.\n- **String Manipulation**: Using `push_str()` to append borrowed string slices to a mutable `String`.\n\n---\n\n## 🔥 Running the Program\n### 1️⃣ Ensure you have Rust installed:\n```sh\nrustc --version\n```\nIf Rust is not installed, install it using:\n```sh\ncurl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh\n```\n\n### 2️⃣ Compile and Run the Program:\n```sh\nrustc main.rs\n./main\n```\nOR using Cargo:\n```sh\ncargo run\n```\n\n---","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyomnaali22%2Frust_simple_programs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyomnaali22%2Frust_simple_programs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyomnaali22%2Frust_simple_programs/lists"}