Docs rewrite
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
---
|
||||
title: Traits & Impls
|
||||
description: Defining traits, trait bounds, and implementation blocks.
|
||||
icon: Puzzle
|
||||
---
|
||||
|
||||
### Traits
|
||||
|
||||
```mist
|
||||
pub trait Drawable {
|
||||
void draw(&self);
|
||||
}
|
||||
|
||||
pub trait Comparable<T> : Eq {
|
||||
i32 cmp(&self, T other);
|
||||
}
|
||||
```
|
||||
|
||||
Trait requirements are specified after `:`:
|
||||
|
||||
```mist
|
||||
trait MyTrait : SuperTrait + OtherTrait {
|
||||
void required_method(&self);
|
||||
void another(&self);
|
||||
}
|
||||
```
|
||||
|
||||
### Impl Blocks
|
||||
|
||||
```mist
|
||||
impl MyType {
|
||||
void method(&self) { }
|
||||
}
|
||||
|
||||
impl Trait for MyType {
|
||||
void method(&self) { }
|
||||
}
|
||||
|
||||
impl<T> GenericTrait<T> for MyType {
|
||||
void method(&self, T value) { }
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user