units: Remove InputString from the public API#3848
units: Remove InputString from the public API#3848tcharding wants to merge 2 commits intorust-bitcoin:masterfrom
InputString from the public API#3848Conversation
|
Needs rebase. Also why did you convert this function to a macro? Also, do these new methods need to be |
Answer in 2 parts:
Woops that's 3 parts. |
0016952 to
c269310
Compare
|
Needs another rebase, sorry. Re "without too much trickery", I'll give it a shot when I do a full review. |
c269310 to
0c355fc
Compare
|
🚨 API BREAKING CHANGE DETECTED To see the changes click details on "Check semver breaks / PR Semver - stable toolchain" job then expand "Run semver checker script" and scroll to the end of the section. |
|
Re the macro, it seems it can be replaced with the function fn to_int<T: FromStr<Err = core::num::ParseIntError> + TryFrom<i8>>(s: &str) -> Result<T, ParseIntError> {
s.parse().map_err(|error| {
ParseIntError {
input: s.into(),
bits: u8::try_from(core::mem::size_of::<T>() * 8).expect("max is 128 bits for u128"),
// We detect if the type is signed by checking if -1 can be represented by it
// this way we don't have to implement special traits and optimizer will get rid of the
// computation.
is_signed: T::try_from(-1i8).is_ok(),
source: error,
}
})
}(though you should fix the formatting). This is just a copy/paste of your macro but with |
|
Mad, thanks. Will re-spin. |
|
Ah woops, my bad. The proper answer to your original question of why did I use a macro is that using a function (like you posted) introduces an allocation in the error path but the macro moves the input string if its a |
|
Then we can make |
|
We can't do that because we don't have |
|
You can do it by taking Having said that, ok, I'm okay with the macro since the signature of the function winds up being a real mouthful. But if we stick with it, I'd like a more explicit comment on it explaining why we're using the macro rather than a generic function. The complicated function signature at least has the benefit of demonstrating exactly what we're trying to do. |
|
Oooo I missed that its private so fine to use |
Currently `InputString` is in the public API of `units` because of the trait bound on `parse::int()`. We can just do the monomorphisisation manually to remove it. This patch renames `int` to have three different names, one for `&str` one for `String`, and one for `Box<str>`.
0c355fc to
1b51a38
Compare
|
No more macro. I totally overcomplicated this PR by failing to realize there was nothing wrong with the current code except that it was public. |
|
I did not close, bad GitHub - no biscuit. |
|
I clicked re-open and its not open, what is going on here? |
|
open sesame |
|
Will try again later. Please click re-open @apoelstra if you read this. |
|
You force-pushed while it was closed, and this perma-closes PRs because Github is idiotic. |
|
O, TIL. Cheers. |
Currently
InputStringis in the public API ofunitsbecause of the trait bound onparse::int(). We can just do the monomorphisisation manually to remove it.This patch renames
intto have three different names, one for&strone forString, and one forBox<str>e.g.,units::parse::int_from_str.Close #3708