Repository navigation
Optimize vec<T> for ToProxy - #20
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fix #3. Implements a Rust version of Leibniz equality
ToProxygetsconst IS_ID: boolandfn cast<F: TypeCtor>(x: F::Apply<Self>) -> Result<F::Apply<Self::Output>, F::Apply<Self>>. By default,castreturnsErr(x), handing the value back so the caller can iterateIS_ID = trueand returnOk(x): String, the primitives, and pass-through structs/enums/flags. That type-checks only becauseOutput == Selfin those impls.TypeCtor { type Apply<X>; }encodes a "type with a hole" using a generic associated type. The constructors areId,InVec,InOption,InResultOk,InResultErr, andInTuple{n}_{i}for each tuple position.Vec,Option,Resultand tuples passcastdown to their element types, adding one constructor layer each. Result and tuples check IS_ID first, so a cast can never fail halfway through.Vec::to_proxytriesT::cast::<InVec<Id>>(self)first and only iterates if that fails. Once compiled, the identity case just returns theVecit was given.As a result, any nesting of
Vec,Option,Resultand tuples over identity types now converts with no per-element work, e.g.Vec<Vec<u8>>,Vec<(String, Vec<u8>)>orVec<Result<Option<…>, ()>>. Types that really need converting go through the old per-element path, unchanged.Requires Rust ≥ 1.65 (GATs)