Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do all generic types implement the Copy trait?

Tags:

rust

Do all generic types in Rust implement the Copy trait? To expand upon this, are there a lot of types in the standard library that implement this trait, other than that of generic types?

like image 737
D. Ataro Avatar asked Mar 13 '26 05:03

D. Ataro


1 Answers

Do all generic types in Rust contain the Copy trait?

No. That's why you have to explicitly request that a generic type implement Copy:

fn foo<T>(value: T)
    where T: Copy,
{
    // ...
}

are there a lot of types in the standard library that implement this trait,

See for yourself. A trait's documentation lists its known implementors.

like image 159
Shepmaster Avatar answered Mar 14 '26 21:03

Shepmaster



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!