Docs
This commit is contained in:
parent
8ce4b0abcc
commit
eb6df9e8f8
@ -20,7 +20,7 @@ After some bitterness we realized it is not possible to capture everything compi
|
||||
want to encounter problems at run time either. The solution is to perform checking at 'test time' to
|
||||
uncover problems. These checks will be removed at production so there will be no run time penalty.
|
||||
|
||||
## Readability
|
||||
## API style
|
||||
|
||||
### Turbofish and inference
|
||||
|
||||
@ -65,4 +65,35 @@ has_many(cake::Entity, cake::Column::Id, fruit::Column::CakeId)
|
||||
we'd prefer having a builder and stating the params explicitly:
|
||||
```rust
|
||||
has_many(cake::Entity).from(cake::Column::Id).to(fruit::Column::CakeId)
|
||||
```
|
||||
|
||||
### Method overloading
|
||||
|
||||
Consider the following two methods, which accept the same parameter but in different forms:
|
||||
|
||||
```rust
|
||||
fn method_with_model(m: Model) { ... }
|
||||
fn method_with_active_model(a: ActiveModel) { ... }
|
||||
```
|
||||
|
||||
We would define a trait
|
||||
|
||||
```rust
|
||||
pub trait IntoActiveModel {
|
||||
fn into_active_model(self) -> ActiveModel;
|
||||
}
|
||||
```
|
||||
|
||||
Such that `Model` and `ActiveModel` both impl this trait.
|
||||
|
||||
In this way, we can overload the two methods:
|
||||
|
||||
```rust
|
||||
pub fn method<A>(a: A)
|
||||
where
|
||||
A: IntoActiveModel,
|
||||
{
|
||||
let a: ActiveModel = a.into_active_model();
|
||||
...
|
||||
}
|
||||
```
|
Loading…
x
Reference in New Issue
Block a user