3 ms·
There is an answer to this. Just `.clone()`, `.to_owned()`, `Arc::new`, and `Mutex::new` like a madman. Sure it’s visual garbage. Yes it impacts the semantics o
by indiv0 4y ago
There is an answer to this. Just `.clone()`, `.to_owned()`, `Arc::new`, and `Mutex::new` like a madman.
Sure it’s visual garbage. Yes it impacts the semantics of your program. Yes it wastes memory. Who gives a crap?
Those four things break you free of the borrow checker while also letting you get a grip on the language.
The docs don’t advocate this approach. Presumably because they favour correctness and understanding over blind hacks. I get why the docs are the way they are but I don’t think it’s worth the blood sacrifice necessary to stay on Mr. Borrow Checker’s Wild Ride.
Note that the above advice is no longer a 100% hammer-fits-all solution because futures and async and pin have unleashed brand new eldritch horrors upon us.
- ModernMech 4y ago> Those four things break you free of the borrow checker while also letting you get a grip on the language. Technically those methods don't break free of the borrow checker; they satisfy the borrow checker by not borrowing.
- deleted 4y ago[deleted]
- ncmncm 4y agoIn other words, do enormously more work, that will then have to be undone, just for lack of a build flag. Nice. Rust absolutely can still fizzle, and certainly will be found to have done, in time, without major improvements in adoption rate. If you have better ideas for that, propose those. The more the better. Spurious objections to ways to improve adoption favor other languages.
- indiv0 4y agoEh I wouldn’t say enormously. The latter two are hyper powerful but hyper rare because how often is a newbie using threads? The former two are just a method call you add to the offending line when the borrow checker complains, and not a moment sooner. It tells you what’s wrong, you fix it, you move on. It’s no different than forgetting a semicolon in Java. Nothing needs to be undone after. Either those 4 tools get you a valid program or you made a logic mistake you would’ve made in any other language. Or in Rust sans borrow checker. I don’t see how that’s an issue. I don’t see how my methods are spurious objections or how I’ve spuriously objected to anything. My methods are tested, tried, and proven to work on a sample of n=1. All that’s left is government funding and we can start mass human trials next month.
- avgcorrection 4y agoIt has already been demonstrated to you that you just can’t “add a build flag”. Your suggestion is unworkable (no matter how many italicized words you sprinkle in). Adding `.to_owned()` will at least work (see, now I’m doing it too)—however much you may dislike it—and doesn’t suffer from the problem of being a pipe dream. You can try to take your “fizzle” comments to /r/rust. See how many people care about Rust being on its deathbed due to not adopting your misguided suggestion.
- aib 4y ago> Who gives a crap? Those four things break you free of the borrow checker while also letting you get a grip on the language. Exactly! And remember, it's not always getting a grip on the language. Sometimes it's getting a grip on the problem or one of the possible solutions.