A pair reads text one way where a currency reads two #25

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

Currency reads text two ways: FromStr (src/lib.rs:1165) and
TryFrom<&str> (src/lib.rs:1173), the second delegating to the first. Both
"USD".parse::<Currency>() and Currency::try_from("USD") work, and a caller
picks whichever reads better where they stand.

Pair implements only FromStr (src/exchange/rate.rs:489), so
Pair::try_from("USD/EUR") fails to compile on the line beneath a
Currency::try_from that compiles. The guidelines want both conversions where
the crate offers either (C-CONV-TRAITS), and the crate has already settled which
shape it prefers one file over.

impl TryFrom<&str> for Pair {
    type Error = ParsePairError;

    fn try_from(notation: &str) -> Result<Self, Self::Error> {
        notation.parse()
    }
}

Additive; nothing breaks.

`Currency` reads text two ways: `FromStr` (`src/lib.rs:1165`) and `TryFrom<&str>` (`src/lib.rs:1173`), the second delegating to the first. Both `"USD".parse::<Currency>()` and `Currency::try_from("USD")` work, and a caller picks whichever reads better where they stand. `Pair` implements only `FromStr` (`src/exchange/rate.rs:489`), so `Pair::try_from("USD/EUR")` fails to compile on the line beneath a `Currency::try_from` that compiles. The guidelines want both conversions where the crate offers either (C-CONV-TRAITS), and the crate has already settled which shape it prefers one file over. ```rust impl TryFrom<&str> for Pair { type Error = ParsePairError; fn try_from(notation: &str) -> Result<Self, Self::Error> { notation.parse() } } ``` Additive; nothing breaks.
rosa closed this issue 2026-08-15 04:46:52 +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#25
No description provided.