/
spirzen
/
it-code-examples
Обзор
Документация
Войти
/
spirzen
/
it-code-examples
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
scripts/oop-practice-sources/rust/figure.rs
55 строк
974 B
Spirzen
OOP
09 июн 2026, 20:58
09 июн 2026, 20:58
1dca232
Код
Авторство
О чём код?
struct Figure { name: String, color: String, } impl Figure { fn describe(&self) { println!("Фигура «{}», цвет: {}", self.name, self.color); } } struct Circle { figure: Figure, } impl Circle { fn new(color: &str) -> Self { Self { figure: Figure { name: "Круг".to_string(), color: color.to_string(), }, } } fn describe(&self) { self.figure.describe(); } } struct Square { figure: Figure, } impl Square { fn new(color: &str) -> Self { Self { figure: Figure { name: "Квадрат".to_string(), color: color.to_string(), }, } } fn describe(&self) { self.figure.describe(); } } fn main() { let circle = Circle::new("красный"); let square = Square::new("синий"); circle.describe(); square.describe(); }