| Crates.io | dynasty-rs |
| lib.rs | dynasty-rs |
| version | 0.2.0 |
| created_at | 2025-02-05 19:14:36.19629+00 |
| updated_at | 2025-02-09 21:00:16.950756+00 |
| description | A powerful class inheritance system for Rust game engines |
| homepage | |
| repository | https://github.com/tristanpoland/dynasty |
| max_upload_size | |
| id | 1544615 |
| size | 25,766 |
Dynasty is a powerful inheritance system for Rust, designed specifically for game engines and complex application architectures. It provides a natural class-based inheritance model while maintaining Rust's safety guarantees and performance characteristics.
Add Dynasty to your Cargo.toml:
[dependencies]
dynasty = "0.1.0"
Create your class hierarchy:
use dynasty::prelude::*;
// Define a base class
#[derive(Class, Debug)]
pub struct Entity {
id: u64,
name: String,
}
// Create a derived class
#[inherit(Entity)]
#[derive(Debug)]
pub struct Character {
// Base field is automatically added by the macro
health: f32,
level: u32,
}
// Multiple levels of inheritance
#[inherit(Character)]
#[derive(Debug)]
pub struct Player {
// Base field is automatically added by the macro
experience: u32,
}
fn main() {
// Create instances
let player = Player {
base: Character {
base: Entity {
id: 1,
name: "Hero".to_string(),
},
health: 100.0,
level: 1,
},
experience: 0,
};
// Use safe downcasting
let as_character: &Character = player.as_parent();
println!("Character level: {}", as_character.level);
}
Enable the reflection feature to access runtime type information:
[dependencies]
dynasty = { version = "0.1.0", features = ["reflection"] }
use dynasty::prelude::*;
#[derive(Class)]
struct Transform {
position: (f32, f32, f32),
}
// Implement reflection
impl Reflect for Transform {
fn get_field(&self, name: &str) -> Option<&dyn Any> {
match name {
"position" => Some(&self.position),
_ => None,
}
}
}
Enable serialization support:
[dependencies]
dynasty = { version = "0.1.0", features = ["serialization"] }
use dynasty::prelude::*;
use serde::{Serialize, Deserialize};
#[derive(Class, Serialize, Deserialize)]
struct GameObject {
id: u64,
components: Vec<Box<dyn Component>>,
}
Dynasty is organized as a workspace with two main crates:
dynasty: The core runtime library providing the inheritance systemdynasty-macros: Procedural macros for the derive and attribute implementationsDynasty is designed with performance in mind:
Check out these examples to see Dynasty in action:
use dynasty::prelude::*;
#[derive(Class)]
struct Component {
enabled: bool,
}
#[inherit(Component)]
struct RigidBody {
mass: f32,
velocity: (f32, f32, f32),
}
#[inherit(Component)]
struct MeshRenderer {
mesh: String,
material: String,
}
use dynasty::prelude::*;
#[derive(Class)]
struct Event {
timestamp: f64,
}
#[inherit(Event)]
struct CollisionEvent {
entity_a: u64,
entity_b: u64,
point: (f32, f32, f32),
}
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
To get started:
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)Licensed under either of:
at your option.
Built with ❤️ by Tristan J. Poland