最近,我想为3D投影编写一个包含参数的类型:
use std::ops::Range;
#[derive(Clone, Copy)]
struct CamProj {
/// Near and far plane
proj_range: Range<f32>,
/// Field of view
fov: cgmath::Rad<f32>, // `Rad` derives `Copy`
/// Width divided by height
aspect_ratio: f32,
}
然而,我遇到了这个错误:
error[E0204]: the trait `Copy` may not be implemented for this type
--> <anon>:3:21
|
3 | #[derive(Clone, Copy)]
| ^^^^
...
6 | proj_range: Range<f32>,
| ---------------------- this field does not implement `Copy`
显然,即使T是Copy类型,例如f32,Range<T>
也从未实现Copy
。 为什么呢? 我以为Range<T>
只是一对T
,所以它肯定可以实现Copy
?