You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The ergonomic problem is that doing this every time is a lot of typing, so it's easier to define a concrete type like:
use std::io::Stdout;fnstart_buildpack<W>(mutoutput:Print<Header<Stdout>>) -> Print<Bullet<Stdout>>{
output.h2("Example Buildpack")}
The most common outputs are stdout and stderr, so we could make type aliases for them so you could use Print<Header> instead of needing to type Print<Header<Stdout>>, but we could take it even further by removing the need to have a Print prefix. The implementation would look kinda like this:
However, the impact is that it would lock each file into a specific output type, if we provide a stdout and stderr variant they could swap between the two easilly. It diverges from the interface of bullet_stream::state module as they would have the same name but mean semantically different things (i.e. one is a Print<Header> while the other is a Header). Another impact is that the person reading the code isn't immediately clear what the argument is being used for. I.e. a Print<Header<Stdout>> is quite descriptive, a Header could be an HTTP header or a markdown streaming header (as in this case). Basically I don't know if the indirection is helpful or not.
So it seems like making this available would make the code possibly easier to write, but possibly harder to read (if the user is unfamiliar with the API). I'm leaning towards not doing this. It's not that hard for people to do this themselves if they wanted in their own repos. But maybe I would like to document these use cases and patterns for people who are newer to Rust.
The text was updated successfully, but these errors were encountered:
The current API looks like this in it's fully generic form:
The ergonomic problem is that doing this every time is a lot of typing, so it's easier to define a concrete type like:
The most common outputs are stdout and stderr, so we could make type aliases for them so you could use
Print<Header>
instead of needing to typePrint<Header<Stdout>>
, but we could take it even further by removing the need to have aPrint
prefix. The implementation would look kinda like this:So we've gone from
to
Which is significant typing savings.
However, the impact is that it would lock each file into a specific output type, if we provide a stdout and stderr variant they could swap between the two easilly. It diverges from the interface of
bullet_stream::state
module as they would have the same name but mean semantically different things (i.e. one is a Print<Header> while the other is a Header). Another impact is that the person reading the code isn't immediately clear what the argument is being used for. I.e. aPrint<Header<Stdout>>
is quite descriptive, aHeader
could be an HTTP header or a markdown streaming header (as in this case). Basically I don't know if the indirection is helpful or not.So it seems like making this available would make the code possibly easier to write, but possibly harder to read (if the user is unfamiliar with the API). I'm leaning towards not doing this. It's not that hard for people to do this themselves if they wanted in their own repos. But maybe I would like to document these use cases and patterns for people who are newer to Rust.
The text was updated successfully, but these errors were encountered: