Skip to content

Returning &Self #9

@U007D

Description

@U007D

Given the following trait:

pub trait Chal {
    fn set_mech_brakes(&self, amt: BrakeAmt) -> &Self;
    fn mech_brakes(&self) -> BrakeAmt;
}

I have tried:

mock_trait!(ChalMock,
            set_brakes(BrakeAmt) -> &Self,
            brakes() -> BrakeAmt);

impl Chal for ChalMock {
    mock_method!(set_mech_brakes(&self, amt: BrakeAmt) -> &Self);
    mock_method!(mech_brakes(&self) -> BrakeAmt);
}

but this yields:

error[E0411]: cannot find type `Self` in this scope
 --> shal_proto/src/unit_tests.rs:7:38
  |
7 |             set_brakes(BrakeAmt) -> &Self,
  |                                      ^^^^ `Self` is only available in traits and impls

error[E0106]: missing lifetime specifier
 --> shal_proto/src/unit_tests.rs:7:37
  |
7 |             set_brakes(BrakeAmt) -> &Self,
  |                                     ^ expected lifetime parameter

error: aborting due to 2 previous errors

I tried:

mock_trait!(ChalMock,
            set_brakes(BrakeAmt) -> &ChalMock,
            brakes() -> BrakeAmt);

impl Chal for ChalMock {
    mock_method!(set_mech_brakes(&self, amt: BrakeAmt) -> &ChalMock);
    mock_method!(mech_brakes(&self) -> BrakeAmt);
}

which helps, but I am still left with:

error[E0106]: missing lifetime specifier
 --> shal_proto/src/unit_tests.rs:7:37
  |
7 |             set_brakes(BrakeAmt) -> &ChalMock,
  |                                     ^ expected lifetime parameter

error: aborting due to previous error

How can I make a mock of Chal using double?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions