One of the things that I love about Rust is the ability to use its flexible type system to enforce many different kinds of constraints at compile time with no cost at runtime. This can sometimes come at the cost of complex type signatures. Recently I hit an error which contained the following type (as you can see, I am working with the futures
crate):
futures::stream::ForEach<futures::stream::MapErr<futures::stream::Zip<tokio_core::net::Incoming, futures::stream::IterOk<std::ops::RangeFrom<usize>, std::io::Error>>, [closure@src/lib.rs:175:18: 175:24]>, [closure@src/lib.rs:176:19: 187:10 new_codec:F, controller:sink_splitter::Controller<usize, futures::sink::SinkMapErr<futures::stream::SplitSink<tokio_io::codec::Framed<tokio_core::net::TcpStream, C>>, [closure@src/lib.rs:179:56: 179:62]>>, mux_sender:futures::unsync::mpsc::UnboundedSender<(usize, II)>, handle:&tokio_core::reactor::Handle], std::result::Result<(), ()>>
I would love it if this type were printed something like:
futures::stream::ForEach<
futures::stream::MapErr<
futures::stream::Zip<
tokio_core::net::Incoming,
futures::stream::IterOk<
std::ops::RangeFrom<usize>,
std::io::Error
>
>,
[closure@src/lib.rs:175:18: 175:24]
>,
[closure@src/lib.rs:176:19: 187:100
new_codec:F,
controller:sink_splitter::Controller<
usize,
futures::sink::SinkMapErr<
futures::stream::SplitSink<
tokio_io::codec::Framed<
tokio_core::net::TcpStream,
C
>
>,
[closure@src/lib.rs:179:56: 179:62]
>
>,
mux_sender:futures::unsync::mpsc::UnboundedSender<
(usize, II)
>,
handle:&tokio_core::reactor::Handle
],
std::result::Result<(), ()>
>
I realize that this is not a fully-formed proposal yet. Some of the open questions that I can think of include:
- Is there better way to approach the problem of making complex types easier to understand?
- When should types should be displayed as multiple lines? Above, Iāve shown
std::ops::RangeFrom<usize>
as a single line rather than splitting it onto multiple lines because I find it easier to read as a single line. - How should closures be formatted?
- Are there things besides generic types and closures that will need to be formatted specially?
Is this an idea worth pursuing and, if so, what are the right next steps?