I just build a trait Bar
with 2 functions (alpha()
with implementation and beta()
with only interfaces), and I hope the struct who implement Bar
implements only beta()
, and never implement their own alpha()
.
Is there any way to prevent another struct from implementing their own alpha()
?
trait Bar {
fn alpha(&self) {
println!("you should never implement this function on your own.");
}
fn beta(&self);
}
struct Foo {}
impl Bar for Foo {
fn alpha(&self) {
println!("how do I trigger an error here when a struct implement it's own alpha()?");
}
fn beta(&self) {
println!("implement beta() for Foo");
}
}
fn alpha<T: Bar>
might also work. – Admit