aoc2019 | Advent of Code 2019 in Rust | Learning library
kandi X-RAY | aoc2019 Summary
kandi X-RAY | aoc2019 Summary
Advent of Code 2019 in Rust
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of aoc2019
aoc2019 Key Features
aoc2019 Examples and Code Snippets
Community Discussions
Trending Discussions on aoc2019
QUESTION
So I'm doing this years advent of code and I've come across a borrowing problem:
How to have a struct that accepts closures calling methods from another variable? Here's a minimum example I've managed to come up with. The borrow checker doesn't like that the two closures both borrow values.
If I have a mutex around values then it seems to work but I was hoping for a more elegant solution.
Essentially, I want to have different Brains with different input/output functions where one might just print outputs and another might be adding outputs to a vec.
...ANSWER
Answered 2020-Jan-08 at 00:10You are doing it wrong, you obviously can't do that in rust, you can only have one mutable reference or one and more reference, but not both. Instead of using interior mutability like Mutex
or Cell
, I advice you do use a trait, for example you could do:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install aoc2019
Rust is installed and managed by the rustup tool. Rust has a 6-week rapid release process and supports a great number of platforms, so there are many builds of Rust available at any time. Please refer rust-lang.org for more information.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page