Skip to content

Add IpAddress (net) #50

@vhrcgcom

Description

@vhrcgcom

Description

Implement IpAddress as a ValueObject in the net module.

Spec: enum: V4(IpV4Address) \

Implementation checklist

  • Create src/net/ipaddress.rs
  • Implement ValueObject trait
  • Add #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
  • Export from src/net/mod.rs and prelude
  • Unit tests: valid input · empty input · invalid format · normalisation
  • Doc comment with # Example block
  • Update status in ROADMAP.md from ⬜ to ✅

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or improvement

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions