mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 08:47:12 +03:00
846a983d67
Summary: Like it says in the title. The API between Bytes 1.x has changed a little bit, but the concepts are basically the same, so we just need to change the callsites that were calling `bytes()` and have them ask for `chunk()` instead. This diff attempts to be as small as it can (and it's already quite big). I didn't attempt to update *everything*: I only updated whatever was needed to keep `common/rust/tools/scripts/check_all.sh` passing. However, there are a few changes that fall out of this. I'll outline them here: ## `BufExt` One little caveat is the `copy_to_bytes` we had on `BufExt`. This was introduced into Bytes 1.x (under that name), but we can't use it here directly. The reason we can't is because the instance we have is a `Cursor<Bytes>`, which receives an implementation of `copy_from_bytes` via: ``` impl<T: AsRef<[u8]>> Buf for std::io::Cursor<T> ``` This means that implementation isn't capable of using the optimized `Bytes::copy_from_bytes` which doesn't do a copy at all. So, instead, we need to use a dedicated method on `Cursor<Bytes>`: `copy_or_reuse_bytes`. ## Calls to `Buf::to_bytes()` This method is gone in Bytes 1.x, and replaced by the idiom `x.copy_to_bytes(x.remaining())`, so I updated callsites of `to_bytes()` accordingly. ## `fbthrift_ext` This set of crates provides transports for Thrift calls that rely on Tokio 0.2 for I/O. Unfortunately, Tokio 0.2 uses Bytes 0.5, so that doesn't work well. For now, I included a copy here (there was only one required, when reading from the socket). This can be removed if we update the whole `fbthrift_ext` stack to Bytes 1.x. fanzeyi had been wanting to update this to Tokio 1.x, but was blocked on `thrift/lib/rust` using Bytes 0.5, and confirmed that the overhead of a copy here is fine (besides, this code can now be updated to Tokio 1.x to remove the copy). ## Crates using both Bytes 0.5 & Bytes 1.x This was mostly the case in Mononoke. That's no coincidence: this is why I'm working on this. There, I had to make changes that consist of removing Bytes 0.5 to Bytes 1.x copies. ## Misuse of `Buf::bytes()` Some places use `bytes()` when they probably mean to use `copy_to_bytes()`. For now, I updated those to use `chunk()`, which keeps the behavior the same but keeps the code buggy. I filed T91156115 to track fixing those (in all likelihood I will file tasks for the relevant teams). Reviewed By: dtolnay Differential Revision: D28537964 fbshipit-source-id: ca42a614036bc3cb08b21a572166c4add72520ad |
||
---|---|---|
.. | ||
if | ||
schemas | ||
src | ||
test | ||
Cargo.toml |