DEV Community

Discussion on: Creative Coding in Rust with Nannou

Collapse
 
coolshaurya profile image
Info Comment hidden by post author - thread only visible in this permalink
Shaurya

Running the code gives an error -

  --> src/main.rs:60:1
   |
45 | struct Dot {
   | ---------- previous definition of the type `Dot` here
...
60 | struct Dot {
   | ^^^^^^^^^^ `Dot` redefined here
   |
   = note: `Dot` must be defined only once in the type namespace of this module

error[E0119]: conflicting implementations of trait `std::marker::Copy` for type `Dot`:
  --> src/main.rs:59:24
   |
44 | #[derive(Debug, Clone, Copy)]
   |                        ---- first implementation here
...
59 | #[derive(Debug, Clone, Copy)]
   |                        ^^^^ conflicting implementation for `Dot`

error[E0119]: conflicting implementations of trait `std::clone::Clone` for type `Dot`:
  --> src/main.rs:59:17
   |
44 | #[derive(Debug, Clone, Copy)]
   |                 ----- first implementation here
...
59 | #[derive(Debug, Clone, Copy)]
   |                 ^^^^^ conflicting implementation for `Dot`

error[E0119]: conflicting implementations of trait `std::fmt::Debug` for type `Dot`:
  --> src/main.rs:59:10
   |
44 | #[derive(Debug, Clone, Copy)]
   |          ----- first implementation here
...
59 | #[derive(Debug, Clone, Copy)]
   |          ^^^^^ conflicting implementation for `Dot`
Collapse
 
deciduously profile image
Ben Lovy • Edited

Hi Shaurya,

It looks like you have the Dot struct defined twice in your source file. Compare to the final version found here and make sure you haven't accidentally included that code snippet twice!

Collapse
 
coolshaurya profile image
Shaurya

But in the blog post code snippet, it is defined twice -

/// A circle to paint
#[derive(Debug, Clone, Copy)]
struct Dot {
    color: Color,
    origin: Point,
    radius: f32,
}


/// Things that can be drawn to the screen
trait Nannou {
    fn display(&self, draw: &app::Draw);
    fn update(&mut self);
}

/// A circle to paint
#[derive(Debug, Clone, Copy)]
struct Dot {
    color: Color,
    origin: Point,
    radius: f32,
    max_radius: f32,
    growth_rate: f32,
}

I think you need to update your blog post.

Also the gh repository seems totally different from the code given here - there are more dependencies on the gh repo.

Thread Thread
 
deciduously profile image
Ben Lovy • Edited

Ah, thank you! My mistake indeed, I've removed the extra Dot declaration from the post. It compiles as written on my machine. The lower of those two declarations, with all five members, is correct.

The GitHub repo represents the code snippet at the end of this post, and does extend the Defensive Refactor snippet in a few ways. The final dependency list should look like this:

[dependencies]

anyhow = "1.0"
lazy_static = "1.4"
log = "0.4"
nannou = "0.12"
pretty_env_logger = "0.3"
structopt = "0.3"

Everything other than nannou is added one by one throughout the post.

Some comments have been hidden by the post's author - find out more