Reader small image

You're reading from  Network Programming with Rust

Product typeBook
Published inFeb 2018
Reading LevelIntermediate
PublisherPackt
ISBN-139781788624893
Edition1st Edition
Languages
Concepts
Right arrow
Author (1)
Abhishek Chanda
Abhishek Chanda
author image
Abhishek Chanda

Abhishek Chanda studied computer science at IIEST Shibpur in India and electrical engineering at Rutgers University. He has been working on networking and distributed systems since 2008. Over his career, he has worked with large companies (like Microsoft and Dell) and small startups (Cloudscaling, DataSine) in India, US, and the UK. He is enthusiastic about open source software and has contributed to a number of projects like OpenStack, Nomad etc. He contributes to a number of open source projects. He came across Rust in 2015 and found it to be a perfect fit for writing highly performant systems.
Read more about Abhishek Chanda

Right arrow

Miscellaneous utilities in std::net

Another important type in the standard library is IpAddr, which represents an IP address. Not surprisingly, it is an enum with two variants, one for v4 addresses and the other for v6 addresses. All of these types have methods to classify addresses according to their types (global, loopback, multicast, and so on). Note that a number of these methods are not stabilized yet and hence are only available in the nightly compiler. They are behind a feature flag named ip which must be included in the crate root so that you can use those methods. A closely related type is SocketAddr, which is a combination of an IP address and a port number. Thus, this also has two variants, one for v4 and one for v6. Let's look at some examples:

// chapter3/ip-socket-addr.rs

#![feature(ip)]

use std::net::{IpAddr, SocketAddr};

fn main() {
// construct an IpAddr...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Network Programming with Rust
Published in: Feb 2018Publisher: PacktISBN-13: 9781788624893

Author (1)

author image
Abhishek Chanda

Abhishek Chanda studied computer science at IIEST Shibpur in India and electrical engineering at Rutgers University. He has been working on networking and distributed systems since 2008. Over his career, he has worked with large companies (like Microsoft and Dell) and small startups (Cloudscaling, DataSine) in India, US, and the UK. He is enthusiastic about open source software and has contributed to a number of projects like OpenStack, Nomad etc. He contributes to a number of open source projects. He came across Rust in 2015 and found it to be a perfect fit for writing highly performant systems.
Read more about Abhishek Chanda