Skip to content

Commit

Permalink
#75 unsafe solution
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jan 12, 2023
1 parent c5482f7 commit 2242ad6
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,12 @@ impl FakeRelay {
#[cfg(test)]
impl Relay for FakeRelay {
fn re(&self, _v: u32, _a: &str, _b: &str) -> Result<String> {
// It's impossible to do what the following two lines are
// doing, because "self" is immutable:
// self.g.add(42).unwrap();
// Ok("ν42".to_string())
Ok("ν1".to_string())
let cp = self as *const Self;
let mp = cp as *mut Self;
unsafe {
(&mut *mp).g.add(42).unwrap();
}
Ok("ν42".to_string())
}
}

Expand All @@ -236,6 +237,6 @@ fn relay_modifies_sodg_back() -> Result<()> {
g.add(1).unwrap();
g.bind(0, 1, "foo").unwrap();
let mut relay = FakeRelay::new(g);
assert_eq!(1, relay.find("bar")?);
assert_eq!(42, relay.find("bar")?);
Ok(())
}

0 comments on commit 2242ad6

Please sign in to comment.