diff --git a/content/docs/guide/classes.mdx b/content/docs/guide/classes.mdx index 5926dfa..e4863d2 100644 --- a/content/docs/guide/classes.mdx +++ b/content/docs/guide/classes.mdx @@ -7,8 +7,9 @@ icon: Shapes Mist introduces `class` as syntactic sugar for a Rust struct with a virtual method table (vtable). ```mist -pub class Animal { - str& name, +pub class Animal +{ + str& name; pub constructor(str& name) { @@ -25,19 +26,21 @@ pub class Animal { Class fields can have default initializers: ```mist -class Player { - i32 health = 100, - str& name, +class Player +{ + i32 health = 100; + str& name; } ``` ### Inheritance ```mist -class Dog : Animal { +class Dog : Animal +{ pub constructor(str& name) { - super(name); + super = Super::new(name); } void speak(&self) override @@ -56,6 +59,25 @@ void speak(&self) override(Animal) } ``` +### Implementations + +You can implement directly on the class body: + +```mist +class Circle +{ + constructor() {} + + impl std::fmt::Display + { + Result<(), std::fmt::Error> fmt(&self, Formatter<'_> f) + { + write!(f, "●") + } + } +} +``` + ### Under the Hood A class `Dog : Animal` generates: