diff --git a/Design.md b/DESIGN.md similarity index 71% rename from Design.md rename to DESIGN.md index 73e88227..c14075ac 100644 --- a/Design.md +++ b/DESIGN.md @@ -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) +where + A: IntoActiveModel, +{ + let a: ActiveModel = a.into_active_model(); + ... +} ``` \ No newline at end of file