Crate wrapped_mono
source · [−]Expand description
wrapped_mono
is a safe, lightweight wrapper around the mono library. It allows embedding of the mono runtime inside a rust project. Inside this embedded runtime code written in languages supporting the .NET framework, such as C# and F#, can be run. This allows usage of libraries written in those languages, and using them as a scripting language. The mono runtime is used by many game engines, and this wrapper allows using it with projects written in Rust too.
Safety
Most functions are safe and when invalid data is passed will fail in a controlled way with an error message. There are still some pitfalls, because not all errors can be caught without substantial overhead. Those errors are hard to come by, and should be always clearly marked in the documentation(for example accessing an object after deleting it by deleting domain it is in), and easy to spot.
Definitions of certain words used in documentation:
Managed Code - code which runs in the runtime(e.g. C# code)
Unmanaged code - code which runs outside runtime(in this case Rust code)
More precise explanation
Feature flags
-
unsafe_boxing
— Disables boxing/unboxing safety checks. Normally, when an object is unboxed, it’s type is checked to prevent crashes and errors. Enabling unsafe_unboxing will make wrapped_mono assume that type given by the user is always correct. -
unsafe_arrays
— Disables array safety checks. Normally, when an array is created, it will make checks to ensure that its managed type matches its unmanaged type. -
unsafe_speedup
— Disables all safety checks to slightly speedwrapped_mono
up. Gains are usually negligible and potential errors will have more cryptic messages(Segfaluts instead of failed assertions). USE WITH CAUTION. -
build_test_dlls
— Build test dlls. Enable only for tests, if you want to change test .cs files. -
regen_binds
— Regenerates bindings for mono library -
dump_macro_results
— Dumps code created as results of macros into “macro.dump” file. Use for debugging when macros do not behave as expected. -
referneced_objects
(enabled by default) — Prevents objects in use by rust from being removed by mono runtime, adds slight overhead but is essential for storing objects long term. Can be disabled, but disabling it forces manual management of object lifetimes using GC handles.
Modules
System.Type
type. wrapped_mono
Macros
Structs
ClassProperity
MonoDomain
type.MonoImage
, the part of MonoAssembly
holding CLI code.Option<Object>
.System.Type
Traits
Self::InteropSend::TargetType
must match managed type represented by Class
returned by get_mono_class
.Functions
Attribute Macros
Derive Macros
InteropRecive
trait for any type containing only IteropRecive
implementing memebers. Currently supports only structs, and trivial enums(C-like enums) of size less than u64(C# max enum size).InteropSend
trait for any type containing only IteropSend
implementing members. Currently supports only structs, and trivial enums(C-like enums) of size less than u64(C# max enum size).