{"id":22292278,"url":"https://github.com/locka99/cpp-to-rust-book","last_synced_at":"2025-07-28T23:33:11.021Z","repository":{"id":41846330,"uuid":"70338456","full_name":"locka99/cpp-to-rust-book","owner":"locka99","description":null,"archived":false,"fork":false,"pushed_at":"2022-11-02T17:26:40.000Z","size":551,"stargazers_count":77,"open_issues_count":7,"forks_count":25,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-05T05:11:26.189Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"CSS","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/locka99.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}},"created_at":"2016-10-08T14:58:46.000Z","updated_at":"2025-03-12T05:18:15.000Z","dependencies_parsed_at":"2023-01-20T21:18:56.494Z","dependency_job_id":null,"html_url":"https://github.com/locka99/cpp-to-rust-book","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/locka99/cpp-to-rust-book","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/locka99%2Fcpp-to-rust-book","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/locka99%2Fcpp-to-rust-book/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/locka99%2Fcpp-to-rust-book/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/locka99%2Fcpp-to-rust-book/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/locka99","download_url":"https://codeload.github.com/locka99/cpp-to-rust-book/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/locka99%2Fcpp-to-rust-book/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267604311,"owners_count":24114522,"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-07-28T02:00:09.689Z","response_time":68,"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":[],"created_at":"2024-12-03T17:20:48.770Z","updated_at":"2025-07-28T23:33:10.693Z","avatar_url":"https://github.com/locka99.png","language":"CSS","funding_links":[],"categories":[],"sub_categories":[],"readme":"# A Guide to Porting C/C++ to Rust\n\nThis book is for people familiar with C or C++ who are thinking of using Rust.\n\nBefore we go into what Rust is or why it might be preferable to C/C++ _in some cases_, let's think of software that is mission critical and must not or should not fail.\n\n* Operating system services and daemons\n* Internet of things devices\n* Industrial control software\n* Medical devices - MRI, ultrasound, X-ray, ventilators etc.\n* High availability servers / databases / cloud storage etc.\n* Avionics, telemetry, rocketry, drones etc.\n\nAll this code must run as efficiently and reliably as possible. It must run on devices for days, weeks, months or preferably years without failure. It cannot suffer intermittent freezes, erratic performance, memory leaks, crashes or other issues without impacting on its purpose.\n\nNormally such software would be written in C or C++, but consider these _every day_ bugs that happen in these languages:\n\n* Use after free / Dangling pointers. A program calls an invalid pointer causing a crash.\n* Buffer overruns / underruns. Code writes beyond an allocated buffer causing memory corruption or a page exception.\n* Memory leaks. Code that allocates memory _or resources_ without calling the corresponding free action. C++ provides classes such as smart pointers and techniques like RAII to mitigate these issues but still occur.\n* Data races. Multiple threads write to data at the same time causing corruption or other destabilizing behavior.\n\n## Why Rust?\n\nRust stops these bad things happening **by design**. And it does so without impacting on runtime performance because all of these things are checked at compile time:\n\n* Object lifetimes are tracked automatically to prevent memory leaks and dangling pointers.\n* The length of arrays and collections is enforced.\n* Data race conditions are prevented by strict enforcement of mutex / guards and object ownership.\n\nCode that passes the compiler's checks is transformed into machine code with similar performance and speed as the equivalent C or C++.\n\nThis is a \"zero-cost\" approach. The compiler enforces the rules so that there is zero runtime cost over the equivalent and correctly written program in C or C++. Safety does not compromise performance.\n\nIn addition Rust plays well C. You can call C from Rust or call Rust from C via foreign function interfaces. So you could rewrite a critical section of your codebase while leaving the remainder alone. You can also invoke Rust via the FFI of other languages - for example NodeJS or Python.\n\n## Rust is not a magic wand\n\nDespite the things the language can protect you against, it cannot protect you against the following:\n\n* General race conditions such as deadlocks between threads\n* Halting problems such as a loop that pushes values onto a vector until memory is exhausted.\n* Application logic errors, i.e. errors that have nothing to do with the underlying language, e.g. missing out the line that should say \"if door\\_open { sound\\_alarm\\(\\); }\"\n* Explicit unsafe sections doing unsafe and erroneous things\n* Errors in LLVM or something outside of Rust's control.\n\nAnd rewriting something for the sake of rewriting is never a good idea. Make sure you have a reason to port or rewrite your code.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flocka99%2Fcpp-to-rust-book","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flocka99%2Fcpp-to-rust-book","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flocka99%2Fcpp-to-rust-book/lists"}