Nicola Coretti
Dec 15, 2022
“Time turns the improbable into the inevitable” – Unknown
error[E0384]: cannot assign twice to immutable variable `var`
--> src/main.rs:3:5
|
2 | let var = 1u32;
| ---
| |
| first assignment to `var`
| help: consider making this binding mutable: `mut var`
3 | var = 10u32;
| ^^^^^^^^^^^ cannot assign twice to immutable variable
For more information about this error, try `rustc --explain E0384`.
error: could not compile `playground` due to previous error; 2 warnings emitted
fn consume(_data: Vec<u8>) {}
fn main() {
let data = vec![1u8, 2u8, 3u8];
consume(data);
println!("{:?}",data);
}
error[E0382]: borrow of moved value: `data`
--> src/main.rs:6:21
|
4 | let data = vec![1u8, 2u8, 3u8];
| ---- move occurs because `data` has type `Vec<u8>`, which does not implement the `Copy` trait
5 | consume(data);
| ---- value moved here
6 | println!("{:?}",data);
| ^^^^ value borrowed here after move
|
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
For more information about this error, try `rustc --explain E0382`.
error: could not compile `playground` due to previous error
use std::io::prelude::*;
use std::net::TcpStream;
fn main() -> std::io::Result<()> {
let mut stream = TcpStream::connect("127.0.0.1:34254")?;
stream.write(b"SPAM!!!")?;
stream.read(&mut [0; 128])?;
Ok(())
} // the stream is closed here
use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
let addr_v4 = SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8080);
let addr_v6 = SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 8080, 0, 0);
let addr: SocketAddr = addr_v4.into();
match addr {
SocketAddr::V4(v) => println!("v4: {:?}", v),
SocketAddr::V6(v) => println!("v6: {:?}", v),
};