net_types::ip

Derive Macro GenericOverIp

#[derive(GenericOverIp)]
{
    // Attributes available to this derive:
    #[generic_over_ip]
}
Expand description

Implements a derive macro for [net_types::ip::GenericOverIp]. Requires that #[derive(GenericOverIp)] invocations explicitly specify which type parameter is the generic-over-ip one with the #[generic_over_ip] attribute, rather than inferring it from the bounds on the struct generics.

Consider the following example:

 #[derive(GenericOverIp)]
 #[generic_over_ip(<ARGUMENTS EXPLAINED BELOW>)]
 struct Foo<T>(T);

#[generic_over_ip(T, Ip)] specifies that the GenericOverIp impl should be written treating T as an Ip implementor (either Ipv4 or Ipv6).

#[generic_over_ip(T, IpAddress)] specifies that T is an IpAddress implementor (Ipv4Addr or Ipv6Addr).

#[generic_over_ip(T, GenericOverIp)] specifies that T implements GenericOverIp<I> for all I: Ip. (Notably, we’d like to use this case for the Ip and IpAddress cases above, but we cannot due to issues with conflicting blanket impls.)

#[generic_over_ip()] specifies that Foo is IP-invariant.