Crates.io | bobo |
lib.rs | bobo |
version | 0.1.4 |
source | src |
created_at | 2024-09-21 13:15:34.556103 |
updated_at | 2024-11-21 03:26:45.730441 |
description | an elegant utils library with oop support |
homepage | https://github.com/moluopro/bobo |
repository | https://github.com/moluopro/bobo |
max_upload_size | |
id | 1382210 |
size | 15,353 |
an elegant and powerful rust development tool library
In development, not recommended. The features listed in the documentation are implemented.
Install: cargo add bobo
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();
}
Create multiple classes with multiple properties and methods.
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
:
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));
}
}
}