{"id":26756957,"url":"https://github.com/gregyjames/csharprustinterop","last_synced_at":"2026-02-16T14:33:41.416Z","repository":{"id":282135555,"uuid":"947606287","full_name":"gregyjames/CSharpRustInterop","owner":"gregyjames","description":"Some examples I found useful calling Rust from CSharp","archived":false,"fork":false,"pushed_at":"2025-03-13T03:57:51.000Z","size":17,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-15T03:52:06.845Z","etag":null,"topics":["csharp","csharp-code","dotnet","dotnet-core","dotnetcore","example","examples","ffi","rust","rust-lang","rust-library","rustffi"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gregyjames.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-13T00:40:19.000Z","updated_at":"2025-03-20T14:12:12.000Z","dependencies_parsed_at":"2025-03-13T01:30:47.484Z","dependency_job_id":"473b1c0e-2048-486b-9106-5eafe7ed88a5","html_url":"https://github.com/gregyjames/CSharpRustInterop","commit_stats":null,"previous_names":["gregyjames/csharprustinterop"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregyjames%2FCSharpRustInterop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregyjames%2FCSharpRustInterop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregyjames%2FCSharpRustInterop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregyjames%2FCSharpRustInterop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gregyjames","download_url":"https://codeload.github.com/gregyjames/CSharpRustInterop/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249003954,"owners_count":21196794,"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":["csharp","csharp-code","dotnet","dotnet-core","dotnetcore","example","examples","ffi","rust","rust-lang","rust-library","rustffi"],"created_at":"2025-03-28T15:22:01.673Z","updated_at":"2026-02-16T14:33:41.375Z","avatar_url":"https://github.com/gregyjames.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/gregyjames/CSharpRustInterop/makefile.yml?style=for-the-badge\u0026logo=githubactions\u0026logoColor=white\u0026label=Build)\n![Rust](https://img.shields.io/badge/rust-%23000000.svg?style=for-the-badge\u0026logo=rust\u0026logoColor=white)\n![C#](https://img.shields.io/badge/c%23-%23239120.svg?style=for-the-badge\u0026logo=csharp\u0026logoColor=white)\n  \n\n# CSharpRustInterop\n\nSome examples I found useful calling Rust from CSharp, I'm sure some of these could be further optimized but this is just a starting ground. The ILogger is particularly useful for maintaining logging settings between Rust and C# code contexts. \n\n  \n\n# Examples\n\n 1. Writing to a memory mapped file by getting a `SafeMemoryMappedViewHandle` and passing its pointer to Rust.\n 2. Passing a List of structs to Rust by using `CollectionMarshall` to read as a span and pinning the reference to the first element using `MemoryMarshal.GetReference`\n 3. Passing a heap allocated class to Rust by using `GCHandle.Alloc(obj, GCHandleType.Pinned)` to acquire a handler to a fixed handler and using `AddrOfPinnedObject()` to retrieve the pointer to that object's memory location.\n 4. Writing to a C# ILogger using delegate function stored as global function pointer in Rust\n 5. Reading a Boxed Vector from Rust as a `Span\u003cT\u003e` in CSharp.\n  \n# Running\n```sh\nmake full_run\n```\n# License\nMIT License\n\nCopyright (c) 2025 Greg James\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgregyjames%2Fcsharprustinterop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgregyjames%2Fcsharprustinterop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgregyjames%2Fcsharprustinterop/lists"}