| 1 | // Effectively all the code in this repo is copied with permission from Rust's std library. |
| 2 | // They hold the copyright (http://rust-lang.org/COPYRIGHT) and whatever other rights, but this |
| 3 | // crate is MIT licensed also, so it's all good. |
| 4 | |
| 5 | //! Networking primitives for TCP/UDP communication. |
| 6 | //! |
| 7 | //! This module provides networking functionality for the Transmission Control and User |
| 8 | //! Datagram Protocols, as well as types for IP and socket addresses. It has been ported |
| 9 | //! from std::net to remove the dependency on std. |
| 10 | //! |
| 11 | //! This crate is a WIP, issues, feedback and PRs are welcome as long as they follow the theme of |
| 12 | //! "std::net" clone. |
| 13 | //! |
| 14 | //! # Organization |
| 15 | //! |
| 16 | //! * [`IpAddr`] represents IP addresses of either IPv4 or IPv6; [`Ipv4Addr`] and |
| 17 | //! [`Ipv6Addr`] are respectively IPv4 and IPv6 addresses |
| 18 | //! * [`TcpListener`] and [`TcpStream`] provide functionality for communication over TCP |
| 19 | //! * [`UdpSocket`] provides functionality for communication over UDP |
| 20 | //! * [`SocketAddr`] represents socket addresses of either IPv4 or IPv6; [`SocketAddrV4`] |
| 21 | //! and [`SocketAddrV6`] are respectively IPv4 and IPv6 socket addresses |
| 22 | //! * [`ToSocketAddrs`] is a trait that used for generic address resolution when interacting |
| 23 | //! with networking objects like [`TcpListener`], [`TcpStream`] or [`UdpSocket`] |
| 24 | //! * Other types are return or parameter types for various methods in this module |
| 25 | //! |
| 26 | #![cfg_attr(feature = "std", doc = "[`TcpListener`]: std::net::TcpListener")] |
| 27 | #![cfg_attr(feature = "std", doc = "[`TcpStream`]: std::net::TcpStream")] |
| 28 | #![cfg_attr(feature = "std", doc = "[`UdpSocket`]: std::net::UdpSocket")] |
| 29 | #![cfg_attr( |
| 30 | not(feature = "std"), |
| 31 | doc = "[`TcpListener`]: https://doc.rust-lang.org/std/net/struct.TcpListener.html" |
| 32 | )] |
| 33 | #![cfg_attr( |
| 34 | not(feature = "std"), |
| 35 | doc = "[`TcpStream`]: https://doc.rust-lang.org/std/net/struct.TcpStream.html" |
| 36 | )] |
| 37 | #![cfg_attr( |
| 38 | not(feature = "std"), |
| 39 | doc = "[`UdpSocket`]: https://doc.rust-lang.org/std/net/struct.UdpSocket.html" |
| 40 | )] |
| 41 | #![no_std] |
| 42 | #![deny( |
| 43 | dead_code, |
| 44 | missing_docs, |
| 45 | unused_imports, |
| 46 | unused_must_use, |
| 47 | unused_parens, |
| 48 | unused_qualifications, |
| 49 | warnings |
| 50 | )] |
| 51 | #![cfg_attr(all(feature = "std", feature = "unstable_ip"), feature(ip))] |
| 52 | |
| 53 | #[cfg(not(feature = "std"))] |
| 54 | mod addr; |
| 55 | #[cfg(not(feature = "std"))] |
| 56 | mod helper; |
| 57 | #[cfg(not(feature = "std"))] |
| 58 | mod ip; |
| 59 | #[cfg(not(feature = "std"))] |
| 60 | mod parser; |
| 61 | #[cfg(all(not(feature = "std"), test))] |
| 62 | mod test; |
| 63 | |
| 64 | #[cfg(all(not(feature = "std"), test))] |
| 65 | #[macro_use] |
| 66 | extern crate alloc; |
| 67 | |
| 68 | #[cfg(all(not(feature = "std"), feature = "serde"))] |
| 69 | extern crate serde; |
| 70 | #[cfg(all(not(feature = "std"), feature = "serde"))] |
| 71 | mod de; |
| 72 | #[cfg(all(not(feature = "std"), feature = "serde"))] |
| 73 | mod ser; |
| 74 | |
| 75 | #[cfg(not(feature = "std"))] |
| 76 | pub use addr::{SocketAddr, SocketAddrV4, SocketAddrV6, ToSocketAddrs}; |
| 77 | #[cfg(all(not(feature = "std"), feature = "unstable_ip"))] |
| 78 | pub use ip::Ipv6MulticastScope; |
| 79 | #[cfg(not(feature = "std"))] |
| 80 | pub use ip::{IpAddr, Ipv4Addr, Ipv6Addr}; |
| 81 | |
| 82 | // Re-export std::net types when std is available |
| 83 | #[cfg(feature = "std")] |
| 84 | extern crate std; |
| 85 | #[cfg(all(feature = "std", feature = "unstable_ip"))] |
| 86 | pub use std::net::Ipv6MulticastScope; |
| 87 | #[cfg(feature = "std")] |
| 88 | pub use std::net::{ |
| 89 | IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6, ToSocketAddrs, |
| 90 | }; |