Nalgebra库组件划分不同类型的向量

时间:2018-12-16 00:17:42

标签: rust

前两次尝试都给出了错误,但是第三次​​尝试了。

extern crate nalgebra as na;

fn main() {
    let a: na::Vector2<f32> = na::Vector2::new(0.0f32, 0.0f32);
    let b: na::Vector2<u32> = na::Vector2::new(1u32, 1u32);
    let c = a.component_div(&b); // mismatched types
    let c = a.component_div(&na::convert(b)); // error[E0284]: type annotations required: cannot resolve `<na::constraint::ShapeConstraint as na::constraint::SameNumberOfRows<na::U2, _>>::Representative == _`
    let c = a.component_div(&na::convert::<na::Vector2<u32>, na::Vector2<f32>>(b)); // compiles
}

在不更改let c = _a的类型以及避免其他中间变量的情况下,是否有更好的方法来完成b的第三个版本?

对我来说真是太难受了,按我现在的样子写第三行。

0 个答案:

没有答案