Replace unwrap with io::Result
@@ -4,16 +4,15 @@ use std::io;
const IN: Token = Token(0);
-fn main() {
+fn main() -> io::Result<()> {
// Set up a new socket on port 9000 to listen on.
- let socket = UdpSocket::bind("0.0.0.0:9000".parse().unwrap()).unwrap();
+ let socket = UdpSocket::bind("0.0.0.0:9000".parse().unwrap())?;
// Initialize poller.
- let mut poll = Poll::new().unwrap();
+ let mut poll = Poll::new()?;
// Register our socket with the token IN (defined above) and an interest
// in being `READABLE`.
poll.registry()
- .register(&socket, IN, Interests::READABLE)
- .unwrap();
+ .register(&socket, IN, Interests::READABLE)?;
// Prepare a buffer for the number of events we can handle at a time.
// Someone might wat to echo really fast so lets give it some size.
@@ -23,7 +22,7 @@ fn main() {
// Main loop
loop {
// Poll if we have events waiting for us on the socket.
- poll.poll(&mut events, None).unwrap();
+ poll.poll(&mut events, None)?;
// If we do iterate throuigh them
for event in events.iter() {
// Validate the token we registered our socket with,
@@ -36,7 +35,7 @@ fn main() {
match socket.recv_from(&mut buf) {
Ok((n, from_addr)) => {
// Send the data right back from where it came from.
- let _r = socket.send_to(&buf[..n], from_addr);
+ socket.send_to(&buf[..n], from_addr)?;
}
Err(e) => {
// If we failed to receive data we have two cases
