r/learnrust • • 13d ago

E0308 when assigning an Option<Enum....>?

Hi everyone.

I have this bit of code (Extracted from something much larger) that is throwing up an error as follows:

#[derive(Clone, Debug)]
pub enum CutterComp {
    CompOff,
    LeftFromTool(Option<Expr>),
    RightFromTool(Option<Expr>),
}

Then in a structure definition :

#[derive(Debug, Default)]
struct StateUpdate {
.
.
.
  radius_compensation: Option<CutterComp>,
.
.
}

Then in an impl of Stateupdate :
  fn intepret_block(&mut self) -> Result<(), ErrType> {
  .
  .
  .
   if let Some (c) = self.grouped_gcodes[GCodeGroups::GRadiusComp as usize] {
            match c.0 {
                GCodes::G40 => {
                    trace!("Cutter compensation off");
                    self.radius_compensation = Some<CutterComp::CompOff>;
                }
                GCodes::G41 => {
                    trace!("Cutter compensation left");
                 self.radius_compensation =           Some<CutterComp::LeftFromTool((self.axis.get(&"d")))>;
                }

Where the thing blows up with

error: comparison operators cannot be chained
  --> src/main.rs:259:52
   |
259 |                     self.radius_compensation = Some<CutterComp::CompOff>;
   |                                                    ^                   ^

Any ideas?

Rust usually gets types right almost by magic (Old C hand here), but it seems to think that I have a bool or something.

Rust analyser is saying "expected Option<CutterComp>, found bool" which I do not understand.

2 Upvotes

16 comments sorted by