Show HN: I built a Rust crate for running unsafe code safely
Published on: 2025-05-12 04:28:48
mem-isolate : Run unsafe code safely
mem-isolate runs your function via a fork() , waits for the result, and returns it.
This grants your code access to an exact copy of memory and state at the time just before the call, but guarantees that the function will not affect the parent process's memory footprint in any way.
It forces functions to be memory pure (pure with respect to memory), even if they aren't.
use mem_isolate :: execute_in_isolated_process ; // No heap, stack, or program memory out here... let result = mem_isolate :: execute_in_isolated_process ( || { // ...Can be affected by anything in here unsafe { gnarly_cpp_bindings :: potentially_leaking_function ( ) ; unstable_ffi :: segfault_prone_function ( ) ; heap_fragmenting_operation ( ) ; something_that_panics_in_a_way_you_could_recover_from ( ) ; } } ) ;
Example use cases:
Run code with a known memory leak
Run code that fragments the heap
Run unsafe code
code Run your code 1ms slower (har har 😉, see limitations)
NO
... Read full article.