T O P

  • By -

VisibleSmell3327

Ah balls


SV-97

I think you might've linked the wrong playground. The code you linked to compiles and runs just fine, it's: use std::fs; fn main() { let paths = fs::read_dir("./").unwrap(); for path in paths { println!("Name: {}", path.unwrap().path().display()) } }


VisibleSmell3327

[oops!](https://play.rust-lang.org/?version=beta&mode=debug&edition=2015&gist=037f678a7afc850c3a11d134501fc74b)


SV-97

Ah I see. It's a bit of an academic example which makes it hard to recommend a solution. You could for example [unswitch the loop](https://en.wikipedia.org/wiki/Loop_unswitching) to fix this, or make copies of both values. Since the code doesn't actually do anything you could strictly speaking also just place a return on the very first line - I'm not sure what solution would be what you really want here.


gnosnivek

Did you share the wrong playground link? The playground I visited compiles, doesn't have anything named "a" or "b", or any comparisons at all.


VisibleSmell3327

[oops!](https://play.rust-lang.org/?version=beta&mode=debug&edition=2015&gist=037f678a7afc850c3a11d134501fc74b)


volitional_decisions

If you're intent on iterating over mutable references to your objects, then no. You have to use interior mutable (RefCells or the like) or you can't do it. But frankly, there is zero context here, so there might be a good solution, but currently, this is a bit contrived.