refactor: switch reqs::Order to owned String #11
Merged
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.
This commit changes the internals of the
reqs::Order
struct to use anowned struct rather than a lifetime pointer. The main reason for this
change is to allow implementing
Into<Order>
for structs that don'thave pointer-based representations of strings for products. For example,
consider the following scenario:
If you imagine trying to implement
From<AppOrder> for reqs::Order
itis currently impossible, as you would need to render the pair (eg.
format!("{}-{}", pair.quote, pair.base)
but the generated string wouldnot live long enough to satisfy the lifetime requirement of the
Order<'a>
.Since an order is almost always followed by IO, and the frequency of
making orders is relatively sparse, the performance overhead of
potentially copying a string unnecessarily seems like a worthwhile
sacrifice for ergonomics.
I realize that this is a breaking change and that it might not be worth releasing immediately (or at all) so please reject this PR if you don't think it's worth it. That being said, I did run into this issue when using it in my application - and I think any application that tries to write bindings to multiple exchanges (and thus has it's own "OrderRequest" type) will run into something similar to this.