Crates.io | school_library |
lib.rs | school_library |
version | 1.0.3 |
source | src |
created_at | 2023-11-29 23:44:33.695956 |
updated_at | 2023-11-29 23:55:57.064778 |
description | This Rust library provides structures to manage school-related data, including students, classes, and schools. |
homepage | |
repository | |
max_upload_size | |
id | 1053692 |
size | 20,397 |
Это, что-то вроде представления базы данных об учебных заведениях для начального и средного образований.
Я написал данный код для тренировки всех своих знаний в языке Rust.
This Rust library provides structures to manage school-related data, including students, classes, and schools.
To use this library, add the following to your Cargo.toml
:
[dependencies]
school_library = "1.0.0"
Then, in your Rust code:
use school_library::{School, Class, Student, Grades};
Represents grades for different subjects.
let grades = Grades::new(90, 85, 88, 92, 78, 87, 91, 95, 89);
let random_grades = Grades::gen();
Represents a student with an ID, name, age, and grades.
let student = Student::new(1, String::from("John Doe"), 16, &grades);
Represents a class with a name and a list of students.
let class = Class::new(String::from("Math Class"), vec![student1, student2]);
class.add_student(&new_student);
Represents a school with a name, a number of students, and a list of classes.
let mut school = School::new(String::from("High School"), vec![class1, class2]);
school.add_class(&new_class);
let average_grades = school.average_grades();
let best_class = school.get_best();
Represents grades for different subjects.
Method Signature | Description |
---|---|
fn new(...) -> Grades |
Creates a new Grades instance with given subject grades. |
fn gen() -> Grades |
Generates random grades. |
Represents a student with an ID, name, age, and grades.
Method Signature | Description |
---|---|
fn new(...) -> Student |
Creates a new Student instance. |
Represents a class with a name and a list of students.
Method Signature | Description |
---|---|
fn new(...) -> Class |
Creates a new Class instance. |
fn get_average() -> f32 |
Calculates the average grades for the class. |
fn add_student(&mut self, student: &Student) |
Adds a student to the class. |
Represents a school with a name, a number of students, and a list of classes.
Method Signature | Description |
---|---|
fn new(...) -> School |
Creates a new School instance. |
fn average_grades() -> f32 |
Calculates the average grades for the entire school. |
fn add_class(&mut self, class: &Class) |
Adds a class to the school. |
fn get_best() -> Class |
Finds the class with the best average grades in the school. |