컴파일하면 아래처럼 나온다..
왜 안되는지는 알겠는데 어떻게 고쳐야할지 모르겠어
Small에서 Deref 말고 다른 스마트 포인터(Ref같은거) 받은담에 레퍼런스 복사하는게 맞나?
어케하는게 젤 idiomatic한지 고수님들 힌트좀
error[E0515]: cannot return value referencing local data `option.small_option`
--> test-bigsmall.rs:32:9
|
31 | let small = Small::new(&option.small_option);
| -------------------- `option.small_option` is borrowed here
32 | Self { option, small }
| ^^^^^^^^^^^^^^^^^^^^^^ returns a value referencing data owned by the current function
error[E0505]: cannot move out of `option` because it is borrowed
--> test-bigsmall.rs:32:16
|
29 | impl<'a> Big<'a> {
| -- lifetime `'a` defined here
30 | fn new(option: BigOption) -> Self {
31 | let small = Small::new(&option.small_option);
| -------------------- borrow of `option.small_option` occurs here
32 | Self { option, small }
| -------^^^^^^---------
| | |
| | move out of `option` occurs here
| returning this value requires that `option.small_option` is borrowed for `'a`
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0505, E0515.
For more information about an error, try `rustc --explain E0505`.
playground에 올려
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=8c890f398b613f01629163425807b660
https://doc.rust-lang.org/std/pin/index.html
뭔가 여기서 말하는 내용이 내 상황이랑 같은거같은데 저게 최선인가; 존나복잡하넹
이게 자기참조 구조체인데.. idiomatic하게는 이렇게 안하는쪽으로 설계를 바꿈
현재로썬 딱히 이쁘게 자기참조 구조체 만들 방법이 없다
음 ㅇㅋㅇㅋ 그럼 BigOption을 destructure할수있게만 바꾸면 좀 낫겠다 ㄱㅅㄱㅅ
Pin쓰면 기술적으로 못하는건 아닌데 ㅈㄴ 못생김
https://m.dcinside.com/board/github/17060
글 잘봤음 ㄱㅅㄱㅅ