Into<Pair> turns away a borrowed pair #29

Closed
opened 2026-08-15 04:17:35 +00:00 by rosa · 0 comments
Owner

ExchangeRate::new, Exchange::rate, and Exchange::remove_rate take
P: Into<Pair>, so a caller passes a pair or the two currencies and either
works. A &Pair is neither, so walking a &[Pair] or a borrowed Vec<Pair>
means writing *pair at every call, or .copied() before the loop.

impl From<&Pair> for Pair closes it, since Pair is Copy:

impl From<&Pair> for Pair {
    fn from(pair: &Pair) -> Self {
        *pair
    }
}

Whether it earns its place is the question. The dereference it saves is one
character, and a From<&T> for T impl on a Copy type is an oddity that then
sits in the rendered docs for everyone reading the type. Filed so the decision is
on the record rather than implied by its absence; closing this as wontfix is a
fine outcome.

`ExchangeRate::new`, `Exchange::rate`, and `Exchange::remove_rate` take `P: Into<Pair>`, so a caller passes a pair or the two currencies and either works. A `&Pair` is neither, so walking a `&[Pair]` or a borrowed `Vec<Pair>` means writing `*pair` at every call, or `.copied()` before the loop. `impl From<&Pair> for Pair` closes it, since `Pair` is `Copy`: ```rust impl From<&Pair> for Pair { fn from(pair: &Pair) -> Self { *pair } } ``` Whether it earns its place is the question. The dereference it saves is one character, and a `From<&T> for T` impl on a `Copy` type is an oddity that then sits in the rendered docs for everyone reading the type. Filed so the decision is on the record rather than implied by its absence; closing this as wontfix is a fine outcome.
rosa closed this issue 2026-08-15 05:39:38 +00:00
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
rosa/lucre#29
No description provided.