Comment by knorker
> What I care about is that it's necessary to do this in the first place.
I don't think it is. socket2::Socket has send_to() just as much as UdpSocket does.
(disclaimer: I only looked up the docs, I didn't try to modify the code to strip out needless UdpSocket)
> runtime-unsafe
That's not a thing. You always need to check for errors. seccomp could be blocking your syscalls. Hard drives break such that reads return error.
Getting an Err() from a function does not make it "unsafe", runtime or not.
> the types could be designed to prevent the need for doing this in the first place.
If your type system does not allow you to "bring your own fd (to be managed)", then it's not fit for purpose for the kind of problems Rust aims to solve.
A systems language needs to be able to receive a file descriptor from a C library, and work with it.
> > runtime-unsafe
> That's not a thing.
Yes, it is. See all the work on the subject of "make illegal states unrepresentable". Search for that phrase, it's originally from Yaron Minsky at Jane Street Capital, but it's mainly a pithy characterization of a common goal for languages with strong type systems, like Rust, Haskell, or the ML family. Another way this is expressed is as "static debugging" - the idea that you can debug a significant proportion of a program's bugs statically, using the type system.
That's what I'm referring to here. If it's unfamiliar to you, it will likely take some time to get used to, because it's a significantly different paradigm from the common approach of debugging by running programs, encountering runtime errors, and trying to resolve them. But, instead of getting indignant and objecting to what I'm saying, consider that there might be something for you to learn here.
> You always need to check for errors. seccomp could be blocking your syscalls. Hard drives break such that reads return error.
What do you believe the relevance of this is? You need to check for errors that can't be checked for at compile time. That doesn't mean we should abandon the idea of checking for errors at compile time, or improving the scope of issues that we can detect at compile time.
Errors that are prevented at compile time cannot occur at runtime in principle, and that's an extremely powerful invariant in software development, one that any serious software developer should be aware of, and be able to take advantage of.
Type systems allow you to prove properties of programs that otherwise would need to be debugged and tested at runtime, but to take advantage of that, the types need to be designed appropriately.
> If your type system does not allow you to "bring your own fd (to be managed)", then it's not fit for purpose for the kind of problems Rust aims to solve.
This is a failure of imagination, nothing more. An appropriate type schema for this domain will be able to handle the requirements of the domain.