Ruby Types
Core type definitions for the Rusty Ruby ecosystem, providing a foundation for Ruby-Rust interop.
🎯 Project Overview
Ruby-Types is a crate that provides the core type definitions for the Rusty Ruby ecosystem, including RubyValue, RubyError, and related types. It serves as the foundation for type conversion between Rust and Ruby.
🌟 Key Features
RubyValue: A unified type for representing Ruby values in RustRubyError: Error types for Ruby operationsRubyResult: Result type for Ruby operations- Type Conversion Traits: Traits for converting between Rust and Ruby types
- Lightweight: No external dependencies, making it easy to integrate
- Comprehensive: Covers all Ruby value types
🚀 Quick Start
use ;
// Create a Ruby value
let ruby_string = String;
// Convert from Rust types
let rust_string: String = "Hello, Rust!".to_string;
let ruby_string = rust_string.to_ruby_value;
// Convert to Rust types
let ruby_int = Integer;
let rust_int: i32 = ruby_int.into_rust_value.unwrap;
// Handle Ruby errors
match safe_operation
🏗️ Architecture
Core Types
RubyValue: Represents all possible Ruby values, including integers, floats, strings, arrays, hashes, symbols, booleans, nil, and objectsRubyError: Represents errors that can occur during Ruby operationsRubyResult: A convenience type alias forResult<T, RubyError>
Type Conversion Traits
ToRubyValue: Converts Rust types to Ruby valuesFromRubyValue: Converts Ruby values to Rust typesRubyObject: Trait for Rust types that can be wrapped as Ruby objects
🛠️ Development
# Build the project
# Run tests
# Build in release mode
📚 Usage Examples
Basic Type Conversion
use ;
// Convert Rust types to Ruby values
let ruby_int = 42.to_ruby_value;
let ruby_float = 3.14.to_ruby_value;
let ruby_string = "Hello".to_ruby_value;
let ruby_bool = true.to_ruby_value;
let ruby_nil = .to_ruby_value; // Represents Ruby nil
// Convert Ruby values to Rust types
let rust_int: i32 = ruby_int.into_rust_value.unwrap;
let rust_float: f64 = ruby_float.into_rust_value.unwrap;
let rust_string: String = ruby_string.into_rust_value.unwrap;
let rust_bool: bool = ruby_bool.into_rust_value.unwrap;
// Handle collections
let rust_array = vec!;
let ruby_array = rust_array.to_ruby_value;
let rust_hash = vec!
.into_iter
.;
let ruby_hash = rust_hash.to_ruby_value;
Custom Ruby Objects
use ;
// Create a Person and convert to Ruby value
let person = Person ;
let ruby_person = person.to_ruby_value;
🤝 Contributing
Contributions are welcome! Feel free to open issues or submit pull requests to help improve Ruby-Types.