Description
Implement IpAddress as a ValueObject in the net module.
Spec: enum: V4(IpV4Address) \
Implementation checklist
Implementation detail
Input / Output
IpAddress is an enum, not a simple newtype. Implement after IpV4Address (#48) and IpV6Address (#49).
|
Type |
Alias |
| Input |
String |
IpAddressInput |
| Output |
String — canonical form delegated to the inner variant |
IpAddressOutput |
Structure
pub enum IpAddress {
V4(IpV4Address),
V6(IpV6Address),
}
Construction logic
Try parsing as IPv4 first; if that fails, try IPv6. If both fail, return ValidationError::InvalidFormat.
Extra methods
is_v4() -> bool
is_v6() -> bool
is_loopback() -> bool — delegates to the inner variant.
is_private() -> bool — delegates to the inner variant (IpV6Address always returns false for this).
References
Description
Implement
IpAddressas aValueObjectin thenetmodule.Spec: enum:
V4(IpV4Address)\Implementation checklist
src/net/ipaddress.rsValueObjecttrait#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]src/net/mod.rsandprelude# ExampleblockROADMAP.mdfrom ⬜ to ✅Implementation detail
Input / Output
IpAddressis an enum, not a simple newtype. Implement afterIpV4Address(#48) andIpV6Address(#49).StringIpAddressInputString— canonical form delegated to the inner variantIpAddressOutputStructure
Construction logic
Try parsing as IPv4 first; if that fails, try IPv6. If both fail, return
ValidationError::InvalidFormat.Extra methods
is_v4() -> boolis_v6() -> boolis_loopback() -> bool— delegates to the inner variant.is_private() -> bool— delegates to the inner variant (IpV6Addressalways returnsfalsefor this).References