Refactoring std for ultimate portability

edit io::Error has been on my mind the last few days, but before I dive into that, let me say thanks again for writing this up and pushing this @brson. The post-unix post-windows post-endlessly-growing-stacks-of-leaky-abstractions utopia is my secret personal motivation too :):).


The solution for io::Error is associated error types on core::io traits:

impl<T> std::io::Read  for T where T: core::io::Read,  std::io::Error: From<T::Error> { .. }
impl<T> std::io::Write for T where T: core::io::Write, std::io::Error: From<T::Error> { .. }

Not only does this fix portability, but also allows one to use the core traits to rule out impossible errors. E.g. &mut [u8]: Read<Error = !> + Write<Error = !>.

I am going to dust off https://github.com/QuiltOS/core-io at a hackathon tomorrow to further demonstrate this.

9 Likes