You can’t write code that’s generic over multiple traits, but this should work for any particular trait:
use std::fmt::Debug;
fn f<'a, T:Debug+'a>(x:Foo<T>)->Foo<dyn Debug+'a> {
Foo {
ptr: x.ptr as *const dyn Debug,
weak: x.weak as std::rc::Weak<dyn Debug>
}
}
On nightly, you might be able to do something with CoerceUnsized, but there are enough caveats in the description that I don’t want to attempt an implementation.
Careful with *const dyn Trait. Given your other post, you may end up comparing a fat pointer using crate-specific vtable-metadata: see this clippy lint.
Comparing trait objects pointers compares an vtable addresses which are not guaranteed to be unique and could vary between different code generation units. Furthermore vtables for different types could have the same address after being merged together.