{"id":18768622,"url":"https://github.com/slimenull/rustsharp","last_synced_at":"2025-04-13T06:32:44.936Z","repository":{"id":163946284,"uuid":"614391874","full_name":"SlimeNull/RustSharp","owner":"SlimeNull","description":"Common components for better program design of Rust language","archived":false,"fork":false,"pushed_at":"2023-12-21T13:11:09.000Z","size":204,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-14T09:14:39.718Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","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/SlimeNull.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-03-15T13:50:30.000Z","updated_at":"2024-06-28T13:23:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"79f51f74-e249-42d4-97ce-54879ba28666","html_url":"https://github.com/SlimeNull/RustSharp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SlimeNull%2FRustSharp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SlimeNull%2FRustSharp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SlimeNull%2FRustSharp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SlimeNull%2FRustSharp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SlimeNull","download_url":"https://codeload.github.com/SlimeNull/RustSharp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248674677,"owners_count":21143760,"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-07T19:13:18.859Z","updated_at":"2025-04-13T06:32:42.783Z","avatar_url":"https://github.com/SlimeNull.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RustSharp\n\nUsing Rust coding style in C#.\n\n\n\n## Usage\n\nUse the `Result` to handle method return values and error messages:\n\n```csharp\n// Wrap a method with \"Result\" return value\n\nResult\u003cint, string\u003e ParseInt(string str)\n{\n    try\n    {\n        return Result.Ok(int.Parse(str));\n    }\n    catch (Exception ex)\n    {\n        return Result.Err(ex.Message);\n    }\n}\n\n// Call that method\n\nstring input = Console.ReadLine()!;\nvar result = ParseInt(input);\n\n// Check if value is \"Ok\" or \"Err\"\n\nvar isOk = result.IsOk;\nvar isErr = result.IsErr;\n\n// Match the result values\n\nresult.Match(\n\t(ok) =\u003e {\n        Console.WriteLine($\"The integer you typed is {ok}\");\n    },\n\t(err) =\u003e {\n        Console.WriteLine($\"The string you typed is not a integer, {err}\");\n    });\n\n// You can also use switch statement\n\nswitch (result)\n{\n    case OkResult\u003cint, string\u003e ok:\n        Console.WriteLine($\"The integer you typed is {ok.Value}\");\n        break;\n    case ErrResult\u003cint, string\u003e err:\n        Console.WriteLine($\"The string you typed is not a integer, {err.Value}\");\n        break;\n}\n```\n\nUse `Option` in C#\n\n```csharp\n// Write a simple method with Option return value\n\nOption\u003cfloat\u003e Divide(float a, float b)\n{\n    if (b != 0.0) {\n        return Option.Some(a / b);\n    } else {\n        return Option.None();\n    }\n}\n\n// call that method\n\nvar option = Divide(114, 514);\n\n// Check if the Option has value\n\nvar isSome = option.IsSome;\nvar isNone = option.IsNone;\n\n// Match the result values\n\noption.Match(\n\t(value) =\u003e {\n        Console.WriteLine($\"Result: {value}\");\n    },\n\t() =\u003e {\n        Console.WriteLine(\"No value\");\n    });\n\n// Or use switch statement\n\nswitch (option)\n{\n    case SomeOption\u003cfloat\u003e some:\n        Console.WriteLine($\"Result: {some.Value}\");\n        break;\n    default:\n        Console.WriteLine(\"No value\");\n        break;\n}\n```\n\nCommon methods of Result and Option\n\n```csharp\n// Convert Result to Option\n\nvar result = Result\u003cstring, string\u003e.Ok(\"Success value\");\nvar option = result.Ok();   // returns Option\u003cstring\u003e contains the success value\n\n// Unwrap Result and Option\n\nvar result = Result\u003cstring, string\u003e.Ok(\"Success value\");\nstring value = result.Unwrap();\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslimenull%2Frustsharp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fslimenull%2Frustsharp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslimenull%2Frustsharp/lists"}