bare-types 0.3.0

A zero-cost foundation for type-safe domain modeling in Rust. Implements the 'Parse, don't validate' philosophy to eliminate primitive obsession and ensure data integrity at the system boundary.
Documentation
//! Network-related types for building type-safe network applications.
//!
//! This module provides strongly-typed abstractions for common network concepts,
//! ensuring type safety and preventing common errors in network programming.
//!
//! ## Design Rules
//!
//! All types in this module follow the core design rules, which adhere to
//! [Rust API Guidelines](https://rust-lang.github.io/api-guidelines/):
//!
//! ### 1. Type Safety (C-NEWTYPE, C-CUSTOM-TYPE)
//!
//! - Strong types prevent mixing incompatible values
//! - Arguments convey meaning through types, not `bool` or `Option`
//! - All validation performed at construction time
//! - No runtime errors from invalid states
//! - Invalid states are unrepresentable
//!
//! ### 2. Zero-Cost Abstractions
//!
//! - No runtime overhead compared to using primitive types
//! - All validation happens at compile time or construction
//! - Subsequent operations have zero cost
//! - Use `#[repr(transparent)]` for newtypes over primitive types
//!
//! ### 3. RFC Compliance
//!
//! - Domain names: RFC 1035
//! - Hostnames: RFC 1123
//! - IP addresses: Standard IPv4/IPv6
//!
//! ### 4. Composability (C-COMMON-TRAITS, C-CONV-TRAITS)
//!
//! All types implement standard traits:
//! - **Common traits** (C-COMMON-TRAITS):
//!   - `Debug` for debugging
//!   - `Clone` for copying
//!   - `Display` for formatting
//!   - `Hash` for use in hash maps
//!   - `Eq` and `PartialEq` for equality
//!   - `Ord` and `PartialOrd` for ordering (where applicable)
//!   - `Default` for default values (where applicable)
//! - **Conversion traits** (C-CONV-TRAITS):
//!   - `From` for infallible conversions
//!   - `TryFrom` for fallible conversions
//!   - `AsRef` for cheap borrowed conversions
//!   - `AsMut` for cheap borrowed mutable conversions
//!   - NOT `Into` or `TryInto` (these are blanket impls)
//!
//! ### 5. Security (C-SEND-SYNC, C-GOOD-ERR)
//!
//! - Types are `Send` and `Sync` where possible (C-SEND-SYNC)
//! - Error types implement `std::error::Error`, `Send`, `Sync` (C-GOOD-ERR)
//! - No unsafe code allowed
//! - Sensitive data uses `Zeroize` for automatic memory clearing
//!
//! ### 6. Explicit Over Implicit (C-DEREF, C-CTOR)
//!
//! - Only smart pointers implement `Deref` and `DerefMut` (C-DEREF)
//! - Constructors are static, inherent methods (C-CTOR)
//! - Prefer explicit constructors
//! - Clear, readable code over clever abstractions
//! - No declarative macros except for serde derives
//!
//! ## Types
//!
//! This module includes types for:
//!
//! - IP addresses (IPv4 and IPv6)
//! - Port numbers with validation
//! - Domain names with RFC 1035 validation
//! - Hostnames with RFC 1123 validation
//! - Host type that can represent IP addresses, domain names, or hostnames
//! - Socket addresses combining hosts and ports
//!
//! ## Features
//!
//! This module requires `net` feature to be enabled.
//!
//! ```toml
//! [dependencies]
//! bare-types = { version = "0.1", features = ["net"] }
//! ```
//!
//! ## `no_std` Support
//!
//! This module is fully `no_std` compatible. All types are built on `core::net`
//! (available in Rust 1.82+) and do not require the standard library.
//!
//! To use in a `no_std` environment:
//!
//! ```toml
//! [dependencies]
//! bare-types = { version = "0.1", default-features = false, features = ["net"] }
//! ```
//!
//! The `std` feature can be optionally enabled for `std::error::Error` implementations.

pub mod cidr;
pub mod domainname;
pub mod email;
pub mod host;
pub mod hostname;
pub mod ipaddr;
pub mod ipv4range;
pub mod ipv6range;
pub mod macaddress;
pub mod port;
pub mod socketaddr;
pub mod url;
pub mod uuid;

pub use cidr::{Cidr, CidrError};
pub use domainname::{DomainName, DomainNameError};
pub use email::{Email, EmailError};
pub use host::{Host, HostError};
pub use hostname::{Hostname, HostnameError};
pub use ipaddr::{IpAddr, IpAddrError};
pub use ipv4range::{Ipv4Range, Ipv4RangeError};
pub use ipv6range::{Ipv6Range, Ipv6RangeError};
pub use macaddress::{MacAddress, MacAddressError};
pub use port::{Port, PortError};
pub use socketaddr::{SocketAddr, SocketAddrError, StdConversionError};
pub use url::{Url, UrlError};
pub use uuid::{Uuid, UuidError, UuidVariant};