bare_types/net/mod.rs
1//! Network-related types for building type-safe network applications.
2//!
3//! This module provides strongly-typed abstractions for common network concepts,
4//! ensuring type safety and preventing common errors in network programming.
5//!
6//! ## Design Rules
7//!
8//! All types in this module follow the core design rules, which adhere to
9//! [Rust API Guidelines](https://rust-lang.github.io/api-guidelines/):
10//!
11//! ### 1. Type Safety (C-NEWTYPE, C-CUSTOM-TYPE)
12//!
13//! - Strong types prevent mixing incompatible values
14//! - Arguments convey meaning through types, not `bool` or `Option`
15//! - All validation performed at construction time
16//! - No runtime errors from invalid states
17//! - Invalid states are unrepresentable
18//!
19//! ### 2. Zero-Cost Abstractions
20//!
21//! - No runtime overhead compared to using primitive types
22//! - All validation happens at compile time or construction
23//! - Subsequent operations have zero cost
24//! - Use `#[repr(transparent)]` for newtypes over primitive types
25//!
26//! ### 3. RFC Compliance
27//!
28//! - Domain names: RFC 1035
29//! - Hostnames: RFC 1123
30//! - IP addresses: Standard IPv4/IPv6
31//!
32//! ### 4. Composability (C-COMMON-TRAITS, C-CONV-TRAITS)
33//!
34//! All types implement standard traits:
35//! - **Common traits** (C-COMMON-TRAITS):
36//! - `Debug` for debugging
37//! - `Clone` for copying
38//! - `Display` for formatting
39//! - `Hash` for use in hash maps
40//! - `Eq` and `PartialEq` for equality
41//! - `Ord` and `PartialOrd` for ordering (where applicable)
42//! - `Default` for default values (where applicable)
43//! - **Conversion traits** (C-CONV-TRAITS):
44//! - `From` for infallible conversions
45//! - `TryFrom` for fallible conversions
46//! - `AsRef` for cheap borrowed conversions
47//! - `AsMut` for cheap borrowed mutable conversions
48//! - NOT `Into` or `TryInto` (these are blanket impls)
49//!
50//! ### 5. Security (C-SEND-SYNC, C-GOOD-ERR)
51//!
52//! - Types are `Send` and `Sync` where possible (C-SEND-SYNC)
53//! - Error types implement `std::error::Error`, `Send`, `Sync` (C-GOOD-ERR)
54//! - No unsafe code allowed
55//! - Sensitive data uses `Zeroize` for automatic memory clearing
56//!
57//! ### 6. Explicit Over Implicit (C-DEREF, C-CTOR)
58//!
59//! - Only smart pointers implement `Deref` and `DerefMut` (C-DEREF)
60//! - Constructors are static, inherent methods (C-CTOR)
61//! - Prefer explicit constructors
62//! - Clear, readable code over clever abstractions
63//! - No declarative macros except for serde derives
64//!
65//! ## Types
66//!
67//! This module includes types for:
68//!
69//! - IP addresses (IPv4 and IPv6)
70//! - Port numbers with validation
71//! - Domain names with RFC 1035 validation
72//! - Hostnames with RFC 1123 validation
73//! - Host type that can represent IP addresses, domain names, or hostnames
74//! - Socket addresses combining hosts and ports
75//!
76//! ## Features
77//!
78//! This module requires `net` feature to be enabled.
79//!
80//! ```toml
81//! [dependencies]
82//! bare-types = { version = "0.1", features = ["net"] }
83//! ```
84//!
85//! ## `no_std` Support
86//!
87//! This module is fully `no_std` compatible. All types are built on `core::net`
88//! (available in Rust 1.82+) and do not require the standard library.
89//!
90//! To use in a `no_std` environment:
91//!
92//! ```toml
93//! [dependencies]
94//! bare-types = { version = "0.1", default-features = false, features = ["net"] }
95//! ```
96//!
97//! The `std` feature can be optionally enabled for `std::error::Error` implementations.
98
99pub mod domainname;
100pub mod host;
101pub mod hostname;
102pub mod ipaddr;
103pub mod port;
104pub mod socketaddr;
105
106pub use domainname::{DomainName, DomainNameError};
107pub use host::{Host, HostError};
108pub use hostname::{Hostname, HostnameError};
109pub use ipaddr::{IpAddr, IpAddrError};
110pub use port::{Port, PortError};
111pub use socketaddr::{SocketAddr, SocketAddrError, StdConversionError};