Repository navigation
EN Structs Traits and Methods
Arena Agent edited this page Sep 18, 2026
·
2 revisions
Plix uses data-oriented object features. There is no class-style data inheritance; behavior is attached with impl and shared through trait.
struct Vec2 { x: float, y: float }
impl Vec2 {
func norm2(&self) -> float {
return self.x * self.x + self.y * self.y;
}
}
let v = Vec2 { x: 3.0, y: 4.0 };
say(v.norm2());
در این مدل، داده در struct تعریف میشود و رفتار با impl کنار آن قرار میگیرد. گیرندههای &self و &mut self بهترتیب borrowing خواندنی و تغییرپذیر را مشخص میکنند.
Use traits when several types should provide the same behavior. Keep data ownership explicit at API boundaries.
Learning path: ← Types and Ownership · Modules and Projects →
- Getting Started
- Installation
- Language Reference
- Types and Ownership
- Structs and Traits
- Modules and Projects
- Standard Library
- Error Guide
- Runtime Model
- Architecture
- Compiler Development
- Testing and Tooling
- Cookbook
- Python FFI
- FAQ
- Contributing