Хз зачем, просто по приколу написал
Это, что-то вроде представления базы данных об учебных заведениях для начального и средного образований.
Я написал данный код для тренировки всех своих знаний в языке Rust.
School Rust Library
This Rust library provides structures to manage school-related data, including students, classes, and schools.
Usage
To use this library, add the following to your Cargo.toml:
[]
= "1.0.0"
Then, in your Rust code:
use ;
Grades
Represents grades for different subjects.
let grades = new;
let random_grades = gen;
Student
Represents a student with an ID, name, age, and grades.
let student = new;
Class
Represents a class with a name and a list of students.
let class = new;
class.add_student;
School
Represents a school with a name, a number of students, and a list of classes.
let mut school = new;
school.add_class;
let average_grades = school.average_grades;
let best_class = school.get_best;
API Reference
Grades
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. |
Student
Represents a student with an ID, name, age, and grades.
| Method Signature | Description |
|---|---|
fn new(...) -> Student |
Creates a new Student instance. |
Class
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. |
School
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. |