Skip to content

Loops inside cascade! are not explained well #13

@TPReal

Description

@TPReal

In an example it says:

let hash_map = cascade! {
  HashMap::new();
  ..insert("foo", "bar");
  println!("Look! You can put statements in a cascade!");
  for i in 0..3 {
    println!("You can put loops in here too! Make sure to put a semicolon at the end!");
  };
};

So there's a loop inside cascade!, but it doesn't invoke any ..method. Is it possible to invoke them? Also the remark about semicolon is very vague, what's the rule here? Why should it be there?

My code:

let x = cascade! {
  MultiLinFunc::new_zero(blink_low_brightness);
  ..add_const_segm(t_in_out);
  for i in 0..blink_rep {
    ..add_segm(t_unit, 1.0);
    ..add_segm(t_unit, blink_low_brightness);
  };
  ..add_segm(t_in_out, 0.0);
};

doesn't compile, I get complaints about the two calls inside the loop:

error[E0425]: cannot find function `add_segm` in this scope
  --> src/weather_clock.rs:36:11
   |
36 |         ..add_segm(t_unit, 1.0);
   |           ^^^^^^^^ not found in this scope

error[E0425]: cannot find function `add_segm` in this scope
  --> src/weather_clock.rs:37:11
   |
37 |         ..add_segm(t_unit, blink_low_brightness);
   |           ^^^^^^^^ not found in this scope

So I suppose the crate doc is not clear enough on this. I don't really know if it's supposed to work and I'm just doing something stupid, or it's not expected to work in the first place.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions