코딩Coding/한글Rust강의★내가★공부하려고만듬

LearnRust❤️Need help understanding move & ownership errors

내인생PLUS 2023. 4. 14. 11:57
728x90


Need help understanding move & ownership errors

If there is a better place to get help please let me know

So, I'm hoping I could get some detailed help with a few errors then from there I could fix errors on my own because I get it. [Most of the code is here.](https://github.com/formula1/card-game/tree/master/card-lang-rust)

- [My first problem is here.](https://github.com/formula1/card-game/blob/master/card-lang-rust/src/types/Lexer.rs#L45)
  - I tried to fix ownership by returning `Self` in each function that uses `self`. This way it would use then pass back.
  - I was told to use &self but I still have two errors
    - https://github.com/formula1/card-game/blob/and-self/card-lang-rust/src/types/Lexer.rs
    - `borrowed value does not live long enough`
    - `cannot borrow \`*self\` as mutable because it is also borrowed as immutable
mutable borrow occurs here`
    - [here](https://github.com/formula1/card-game/blob/and-self/card-lang-rust/src/calculator/lexer/tokens/digit.rs) I'm getting `\`l\` is a \`&\` reference, so the data it refers to cannot be borrowed as mutable`
- [Here I'm trying to mutate in loops but rust doesn't like that](https://github.com/formula1/card-game/blob/and-self/card-lang-rust/src/types/Parser.rs#L43)
- [Here I cannot move because it's behind a shared reference](https://github.com/formula1/card-game/blob/and-self/card-lang-rust/src/types/Evaluator.rs#L122)











https://www.reddit.com/r/learnrust/comments/12k8emj/need_help_understanding_move_ownership_errors/?utm_source=share&utm_medium=ios_app&utm_name=ioscss&utm_content=2&utm_term=1

r/learnrust on Reddit: Need help understanding move & ownership errors

Posted by u/DontFearTheCode - 3 votes and 2 comments

www.reddit.com






반응형