Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: switch reqs::Order to owned String
This commit changes the internals of the `reqs::Order` struct to use an owned struct rather than a lifetime pointer. The main reason for this change is to allow implementing `Into<Order>` for structs that don't have pointer-based representations of strings for products. For example, consider the following scenario: ```rust enum Coin { BTC USD } enum Pair { quote: Coin, base: Coin, } enum AppOrder { pair: Pair, size: f64, } ``` If you imagine trying to implement `From<AppOrder> for reqs::Order` it is currently impossible, as you would need to render the pair (eg. `format!("{}-{}", pair.quote, pair.base)` but the generated string would not 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 uneccesarily seems like a worthwhile sacrafice for ergonomics. This commit changes the internals of the `reqs::Order` struct to use an owned struct rather than a lifetime pointer. The main reason for this change is to allow implementing `Into<Order>` for structs that don't have pointer-based representations of strings for products. For example, consider the following scenario: ```rust enum Coin { BTC USD } enum Pair { quote: Coin, base: Coin, } enum AppOrder { pair: Pair, size: f64, } ``` If you imagine trying to implement `From<AppOrder> for reqs::Order` it is currently impossible, as you would need to render the pair (eg. `format!("{}-{}", pair.quote, pair.base)` but the generated string would not 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.
- Loading branch information