Sending struct using crossbeam_channel::bounded

I have very simple struct:

struct WSReadFrame {
    opcode: u8,
    payload: Vec<u8>,
}

In code I need to send it via crossbeam_channel::bounded like so

let (s, r) = bounded::<WSReadFrame>(1024);

...

let send_frame: WSReadFrame = WSReadFrame::new(...);
s.send(send_frame).unwrap();

What I don't get in this snippet is that what will actually happen:

  • send_frame will be moved and only its pointer will actually be sent over the channel, and no bytes will be copied?
  • during send rust will move send_frame and actually send all its content?

Pairs of send/recv are analogous to vec.push() and vec.pop().

2 Likes

So it will send only pointer, right ?

Only the opcode, as well as the pointer, length and capacity of the vector are actually copied. The contents behind the pointer is not.

2 Likes

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.