{"id":18267645,"url":"https://github.com/oxeu/kotlike","last_synced_at":"2025-04-04T22:30:39.071Z","repository":{"id":215951361,"uuid":"740112867","full_name":"OXeu/kotlike","owner":"OXeu","description":"A Rust macro to modify the question mark operator's behavior just like Kotlin's","archived":false,"fork":false,"pushed_at":"2024-01-07T15:47:38.000Z","size":11,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T11:17:36.902Z","etag":null,"topics":["crates","macro","macros-rust","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OXeu.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":"2024-01-07T15:09:31.000Z","updated_at":"2024-01-07T16:11:46.000Z","dependencies_parsed_at":"2024-01-07T17:11:56.813Z","dependency_job_id":"662be3eb-5649-49a8-9e0f-0a9295c10feb","html_url":"https://github.com/OXeu/kotlike","commit_stats":null,"previous_names":["thankrain/kotlike","oxeu/kotlike"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OXeu%2Fkotlike","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OXeu%2Fkotlike/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OXeu%2Fkotlike/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OXeu%2Fkotlike/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OXeu","download_url":"https://codeload.github.com/OXeu/kotlike/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247260281,"owners_count":20909974,"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":["crates","macro","macros-rust","rust"],"created_at":"2024-11-05T11:28:09.652Z","updated_at":"2025-04-04T22:30:38.728Z","avatar_url":"https://github.com/OXeu.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003eKotlike\u003c/h1\u003e\n\u003ch6 align=\"center\"\u003eA Rust macro to modify the question mark operator's behavior just like Kotlin's\u003c/h6\u003e\n\u003cbr/\u003e\n\n\nWith it, you can easily pick out the value wrapped in numberless `Option\u003cT\u003e` and `Result\u003cT,Err\u003e`.\n\nFurthermore, it won't break down your control flow. You can continue your work even you got a `None` or `Err` (All the unexpected value will turn to `None`)\n\nIt means:\n```rust\nfn do_something() {\n    let value: Option\u003cTypeYourWant\u003e = wrapped_value?.something_return_option()?.something_return_result()?.value;\n}\n```\nwould works fine! Just as Kotlin's style.\nAnd you don't need to worry about what `Err` it would throw!\n\n# How it Works\n**Usage**\n```rust\n#[kotlike]\nfn main() {\n    let a = \"Hello\".to_string();\n    \n    let c = File::create(\"test.txt\")?.write_all(a.as_bytes())?.clone();\n    \n    let mut b: String = String::new();\n    \n    let len = File::open(\"test.txt\")?.read_to_string(\u0026mut b)?.clone();\n    \n    println!(\"Hello, {:?}({:?})!\", b,len);\n}\n```\n**Expand the macro would look like**:\n```rust\nfn main() {\n  let a = \"Hello\".to_string();\n    \n  let c: Option\u003c()\u003e = File::create(\"test.txt\")\n      .map_or(None, |mut v| {\n          v.write_all(a.as_bytes())\n              .map_or(None, |mut v| Some(v.clone()))\n      });\n    \n  let mut b: String = String::new();\n    \n  let len: Option\u003cusize\u003e = File::open(\"test.txt\")\n      .map_or(None, |mut v|{\n          v.read_to_string(\u0026mut b)\n              .map_or(None, |mut v| Some(v.clone()))\n      });\n    println!(\"Hello, {:?}({:?})!\", b,len);\n}\n```\nAbove example is just showing how it works. Don't focus too much on what stupid code does.\n\n# LICENSE\n[Apache LICENSE 2.0](LICENSE)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foxeu%2Fkotlike","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foxeu%2Fkotlike","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foxeu%2Fkotlike/lists"}