Closed apoelstra closed 4 weeks ago
How would such a constructor get at the string (bytes) created by the Display
implementation without allocating a string?
We could add convenience constructors but I don't really see the value, what am I missunderstanding?
/// Constructs a `Hrp` for an `hrp` string created by calling `hrp.to_string()`.
pub fn from_display(hrp: impl fmt::Display) -> Result<Self, Error> {
let s = hrp.to_string();
Self::parse(&s)
}
/// Constructs a `Hrp` for an `hrp` string created by calling `hrp.to_string()`.
pub fn from_display_unchecked(hrp: impl fmt::Display) -> Self {
let s = hrp.to_string();
Self::parse_unchecked(&s)
}
By implementing a fmt::Write
backed by an array. I've almost finished this, I'll try to PR shortly.
Concept ACK, and cool implementation in #196
This would allow easy construction from a rust-lightning
RawHrp
. Currently it allocates aString
which is an unnecessary allocation and inconvenient.