Rust seems to be inferring a defined type

49 Views Asked by At

I am programming in Rust for the first time and using the ggez and nalgebra libaries.

Here is the code.

let target = graphics::Mesh::new_circle(
            ctx, 
            graphics::DrawMode::stroke(2.0), 
            self.target_position, 
            20.0, 
            0.2, 
            graphics::Color::BLACK
        )?;
struct SeekFlee {
    // This is the main state, and references the starting state 
    target_position: na::Point2<f32>,
    // position of seek vehicle
    // position of flee vehicle 
}

impl SeekFlee {
    pub fn new(_ctx: &mut Context) -> SeekFlee {
        // load resources if necessary
        let (mid_width, mid_height) = (WIDTH * 0.5, HEIGHT * 0.5);
        let target_pos: na::Point2<f32> = na::Point2::new(mid_width, mid_height);
        SeekFlee {
            target_position : target_pos,
        }
    }
}

I am trying to draw a circle but I keep getting an error where a Point2 is having the type inferred as OPoint<f32, Const<2>>.

This is the error I am getting.

the trait bound `Point2<f32>: From<OPoint<f32, Const<2>>>` is not satisfied
the trait `From<Vec2>` is implemented for `Point2<f32>`
for that trait implementation, expected `Vec2`, found `OPoint<f32, Const<2>>`
required for `OPoint<f32, Const<2>>` to implement `Into<Point2<f32>>`

Any help would be appreciated! The error is in the first block when I try to set the point parameter to target_position.

0

There are 0 best solutions below