I want to notify that "this method will return boxed Struct
which implements Trait
and Sized
".
Simple resolution is just put Struct
into Box
but I can't because Struct
has so big generic parameter that I can't write manually.
// I can't edit these trait and struct.
trait Trait {}
struct Struct();
impl Trait for Struct {}
// This is my code.
fn func() -> Box<Trait> {
Box::new(Struct{})
}
// This is not my code.
fn need_sized<T: Trait + Sized>(item: T) {
println!("ok");
}
fn main() {
// This can not be compiled!
need_sized(func());
}
I can edit func
function but I can't others.
How can I specify that Trait implements Sized? Is it something kind like below?
fn func() -> Box<Trait + Sized>