How do i solve this issue..
Like, why??? why does it say dropped, when in fact i was gonna just await, how does it even make sense
How do i solve this issue..
Like, why??? why does it say dropped, when in fact i was gonna just await, how does it even make sense
Don't post pictures of code.
it had me so overwhelming that i couldn't explain my problem, i couldn't even figure out the correct words for the issue here properly, that's why just to give more context what is going on i posted a picture
If you refuse to put the code and full error message in a format where I can copy-paste it into e.g. an editor, then I wont help you.
error[E0716]: temporary value dropped while borrowed
--> src/work/peer.rs:146:15
|
146 | match peer.borrow_mut().try_connect().await {
| ^^^^^^^^^^^^^^^^^
| |
| creates a temporary which is freed while still in use
| a temporary with access to the borrow is created here ...
...
183 | };
| -
| |
| temporary value is freed at the end of this statement
| ... and the borrow might be used here, when that temporary is dropped and runs the destructor for type `RefMut<'_, Peer<'_>>`
|
= note: consider using a `let` binding to create a longer lived value
I couldn't even understand how the value is going to be dropped here
Code blocks please:
Sorry😓
Looking at your code, it seems like you should just remove the RefCell
entirely.
I could make it workable without using RefCell, but i somehow want to use the peer instance inside that match block to get one of the field's value
let PIECE_LENGTH = details.lock().await.piece_length.unwrap() as u32;
loop {
let mut peer = Peer::new(socket_adr, details.clone());
match peer.try_connect().await {
Some(((mut tcp_sender, mut tcp_receiver), channel_sender)) => {
let y = peer.status.clone();
// Continuosly reads on the stream for some message
let read = async move {
loop {
but it shows me this error now,
error[E0502]: cannot borrow `peer.status` as immutable because it is also borrowed as mutable
--> src/work/peer.rs:148:25
|
146 | match peer.try_connect().await {
| ------------------ mutable borrow occurs here
147 | Some(((mut tcp_sender, mut tcp_receiver), channel_sender)) => {
148 | let y = peer.status.clone();
| ^^^^^^^^^^^^^^^^^^^
| |
| immutable borrow occurs here
| mutable borrow later used here
For more information about this error, try `rustc --explain E0502`.
How do i edit the code in such a way that i can use the peer inside of that match block as well.
I understand here that i borrowed mutably, is there any way to drop that mutable borrow so that i can borrow it mutably again inside of that match block
When it comes to RefCell
, you generally can't use it in async code.
What does try_connect
return?
It's weird! somehow pasting from my clipboard isn't working right now, but i've shown the return type in the second picture i sent
Why does it return something with a lifetime on it?
It basically returns a wrapper around "ReadHalf" and "WriteHalf" of tokio
Why are you not using into_split
?
If you return a mutable reference from the function (there's a mutable reference inside those split halves), then you wont be able to access the value until you stop using that mutable reference.
oh shit..just checked out..never saw that actually....thanks! i just found out about it tbh
Can i ask you one simple question, i'm sort of immature in rust. How long does it usually take to be someone at your caliber?
I believe people out there say that it took them a few months to be really comfortable with Rust.
As for me, I don't think people should try to compare themselves with me — I know Rust far more deeply than you need to to be productive with Rust.
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.