Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Network Programming with Rust

You're reading from  Network Programming with Rust

Product type Book
Published in Feb 2018
Publisher Packt
ISBN-13 9781788624893
Pages 278 pages
Edition 1st Edition
Languages
Concepts
Author (1):
Abhishek Chanda Abhishek Chanda
Profile icon Abhishek Chanda
Toc

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 chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £13.99/month. Cancel anytime}