https://github.com/moluopro/bobo
rust oop support
https://github.com/moluopro/bobo
object-oriented oop rust rust-lang
Last synced: 5 months ago
JSON representation
rust oop support
- Host: GitHub
- URL: https://github.com/moluopro/bobo
- Owner: moluopro
- License: apache-2.0
- Created: 2024-10-15T02:22:34.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-21T03:31:38.000Z (over 1 year ago)
- Last Synced: 2025-10-19T09:31:14.738Z (8 months ago)
- Topics: object-oriented, oop, rust, rust-lang
- Language: Rust
- Homepage:
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## BOBO
an elegant and powerful rust development tool library
> In development, not recommended. The features listed in the documentation are implemented.
### Quick Start
Install: `cargo add bobo`
```rust
use bobo::oop::*;
class! {
Person {
name: String
age: u32
fn greet() {
println!("{}", format!("Hello, my name is {}.", self.name));
}
}
}
fn main() {
let person = Person {
name: String::from("Tom"),
};
person.greet();
}
```
## A more complex example
Create multiple classes with multiple properties and methods.
```rust
use bobo::oop::*;
class! {
Person {
name: String
age: u32
fn greet() {
println!("{}", format!("Hello, my name is {}.", self.name));
}
fn get_age(years: u32) -> u32 {
self.age + years
}
}
Animal {
species: String
age: u32
fn speak() {
println!("The {} makes a sound.", self.species);
}
fn age_in_human_years() -> u32 {
self.age * 7
}
}
}
```
Create a class using a constructor named `new`:
```rust
use bobo::oop::*;
fn main() {
let person = Person::new("Alice", 30);
person.greet();
}
class! {
Person {
name: String
age: u32
fn new(name: &str, age: u32) -> Self {
Self {
name: name.to_string(),
age
}
}
fn greet() {
println!("{}", format!("I'm {}.", self.name));
}
}
}
```