magnus-bindings

Solid

Magnus conventions for building Ruby native extensions from a Rust core: define_class, TryConvert/IntoValue, exception mapping, GVL handling, TypedData GC integration, and rake-compiler distribution. Load when generating or reviewing Magnus Ruby bindings for a Rust library.

Data & Documents 137 stars 13 forks Updated today MIT

Install

View on GitHub

Quality Score: 84/100

Stars 20%
71
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
50
Issue Health 10%
80
License 10%
100
Description 5%
100

Skill Content

- Use `magnus` crate for Ruby native extensions. Define classes with `magnus::define_class`. - Map Rust types to Ruby using `TryConvert` and `IntoValue` traits. Return `Result<T, magnus::Error>`. - Use `magnus::function!` macro for defining Ruby methods. Use `magnus::method!` for instance methods. - Map Rust errors to specific Ruby exceptions: `magnus::Error::new(exception::runtime_error(), msg)`. - Build with `rb_sys` crate and `magnus-build` for compilation. Use `rake-compiler` for gem distribution. - Support Ruby 3.2+ with multiple ABI versions. - Test bindings from Ruby using RSpec or Minitest. Test error handling and edge cases. - Keep Ruby wrapper gem thin — business logic in Rust, Ruby provides idiomatic API. - Handle Ruby's GVL (Global VM Lock) — release for CPU-intensive Rust code. - Use `TypedData` for wrapping Rust structs as Ruby objects with proper GC integration. - Anti-patterns: panics in Ruby methods, `unsafe` without `SAFETY` comments, manual memory management.

Details

Author
Goldziher
Repository
Goldziher/ai-rulez
Created
1 years ago
Last Updated
today
Language
Go
License
MIT

Similar Skills

Semantically similar based on skill content — not just same category