I come from Kotlin, where even something like class MyClass
or interface MyInterface
is compilable. When you don't need a body for your class, you can omit the curly braces entirely.
I have this specific Rust use case that I came across today:
pub trait ReadRepository<T> {
fn get_all(&self) -> Vec<T>;
fn get_by_id(&self, id: i32) -> Option<T>;
}
pub trait CreateRepository<T> {
fn create(&self, data: T) -> T;
}
pub trait UpdateRepository<T> {
fn update(&self, id: i32, data: T) -> Option<T>;
}
pub trait DeleteRepository<T> {
fn delete(&self, id: i32) -> Option<T>;
}
pub trait CRUDRepository<T>:
ReadRepository<T> + CreateRepository<T> + UpdateRepository<T> + DeleteRepository<T>
{
}
As you can see, the CRUDRepository
is just a trait that combines all the other traits above, no need for a body. However, the ugly empty curly braces need to be there for some reason...