is there a rust trait for "this type can be written to an i/o stream as a sequence of bytes"
-
Show this thread
-
Replying to @mountain_ghosts
io::Read seems like the prime suspect. In the async world there's futures::io::AsyncRead which implements `write_into` to directly copy data into an AsyncWrite. Not sure if the sync world has a similar combinator, but the idea should be similar.
1 reply 1 retweet 1 like -
Replying to @yoshuawuyts
oh, yes, you might be right it's not writing to I/O but at least it avoids allocating lots of separate Vecs for each written object
1 reply 0 retweets 1 like -
Replying to @mountain_ghosts @yoshuawuyts
except Read writes into a fixed-size slice, not a growable buffer?
1 reply 0 retweets 0 likes -
Replying to @mountain_ghosts
The slices could be backed by a growable buffer. It makes very few assumptions in its API.
1 reply 0 retweets 0 likes -
-
Replying to @mountain_ghosts @yoshuawuyts
the [u8] might be owned by a Vec but if you're only given a slice reference you can't append to it
1 reply 0 retweets 0 likes -
Replying to @mountain_ghosts
That is accurate, but you can keep growing the buffer between each call on the caller's side until done
2 replies 0 retweets 0 likes
In general there is some interplay between the traits required. And that's where combinators such as `copy_into` become particularly nice to use.
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.