Earlier quoted context omitted.
> The issue is that the rust library apparently conflates datagram and UDP, when they're not the same thing. It comes down to these two lines (using full items paths for clarity): let socket = socket2::Socket::new(Domain::IPV4, Type::DGRAM, Some(Protocol::ICMPV4))?; let socket: std::net::UdpSocket = socket.into(); The latter is using this impl: https://docs.rs/socket2/0.6.1/socket2/struct.Socket.html#imp... Basically…
It may be memory safe but it's not using the type system to represent the domain very well. One could imagine a more type-friendly design in which we could write that first line as follows: let socket: Socket = Socket::new()?; Now, the specifics of socket types will be statically checked. Edit: I realized that the issue here is actually the conversion, and that UdpSocket on its own is actually a type-safe representat…
So now one is making one's own enumeration which is different than the OS one and mapping between them, which can get into a mess of all the various protocols Linux and other OSs support, and I'm not sure it's solving a major problem. Opinions vary, but I prefer to use complex types sparingly.
I think there are likely a bunch of other cases where it's useful to choose these values more dynamically too. Networking gets weird!