Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Shortly, this PR merged
split
andsplit_with
into a single function and removedunsplit
.Instead of
Splitting is a common pattern in Rust, but
embedded-tls
had implemented it in a peculiar way. Unfortunately, this way is not ergonomic and does not compose well.Commonly,
split
exclusively borrowsself
and returns two sides which are using it's data. Original entity cannot be used because it is mutably borrow while children are alive. When both dropped, parent is automatically released by the borrow checker.A good example is
heapless::Queue::split
I tried to use
embedded-tls
with other, traditional, "split" APIs, butunsplit
approach just doesn't work here due to variance issues - you need to have&mut
to put back reader and writer, so you can useunsplit
, but reader and writer are not static, thus lifetime becomes invariant, making it unusable. You can read more about variance in the corresponding rustonomicon section.That PR converted split to the borrowing version and removed a number of not really needed types. Implementations of buffers became a little bit more explicit, to improve borrow checker's behavior.