- Use
magnuscrate for Ruby native extensions. Define classes withmagnus::define_class. - Map Rust types to Ruby using
TryConvertandIntoValuetraits. ReturnResult<T, magnus::Error>. - Use
magnus::function!macro for defining Ruby methods. Usemagnus::method!for instance methods. - Map Rust errors to specific Ruby exceptions:
magnus::Error::new(exception::runtime_error(), msg). - Build with
rb_syscrate andmagnus-buildfor compilation. Userake-compilerfor 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
TypedDatafor wrapping Rust structs as Ruby objects with proper GC integration. - Anti-patterns: panics in Ruby methods,
unsafewithoutSAFETYcomments, manual memory management.
Magnus Bindings
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.
Magnus Bindings by goldziher · bf8fd06
npx skillmds@latest add goldziher/magnus-bindings File contents
---name: magnus-bindingsdescription: 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.---- 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.
goldziher/ai-rulez/tree/main/internal/builtins/bindings/magnus/skills/magnus-bindings commit bf8fd06e26
Frequently asked questions
Run npx skillmds@latest add goldziher/magnus-bindings in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
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. It is listed under Integrations & APIs on SkillMD.
This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
goldziher (@goldziher) published this skill. Their other Agent Skills are listed on their SkillMD profile.