Reputation: 3573
use std::io::Read;
use std::net::TcpListener;
struct Server<'a> {
ip_addr: &'a str,
}
impl<'a> Server<'a> {
fn receive(&self) {
let mut received_message_buf: [u8; 100];
let tcp_listener = TcpListener::bind(self.ip_addr).unwrap();
tcp_listener.accept().unwrap().0.read(&received_message_buf);
}
}
fn main() {}
I'm getting mismatched types:
<anon>:13:47: 13:68 error: mismatched types:
expected `&mut [u8]`,
found `&[u8; 100]`
(values differ in mutability) [E0308]
<anon>:13 tcp_listener.accept().unwrap().0.read(&received_message_buf);
^~~~~~~~~~~~~~~~~~~~~
Upvotes: 0
Views: 5145
Reputation: 2103
You need to use &mut received_message_buf
instead of &
.
&mut
creates a mutable reference (so read()
can put things into your buffer), while &
creates an immutable reference.
Upvotes: 4