-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use IntoUrl for more ergonomic function signatures #520
base: master
Are you sure you want to change the base?
Conversation
Pull Request Test Coverage Report for Build 13090676415Details
💛 - Coveralls |
cACK, I don't think the complexity is too wild, and I agree 100% with this point:
Linking to reqwest::IntoUrl in the module-level documentation or even the commit message would help clearly point to the source of inspiration for our approach. |
payjoin/src/into_url.rs
Outdated
impl std::fmt::Display for Error { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Error::BadScheme => write!(f, "URL scheme is not allowed"), | ||
Error::ParseError(e) => write!(f, "{}", e), | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A neat trick I saw in rust-bitcoin to avoid repetition:
impl std::fmt::Display for Error { | |
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | |
match self { | |
Error::BadScheme => write!(f, "URL scheme is not allowed"), | |
Error::ParseError(e) => write!(f, "{}", e), | |
} | |
} | |
} | |
impl std::fmt::Display for Error { | |
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | |
use Error::*; | |
match self { | |
BadScheme => write!(f, "URL scheme is not allowed"), | |
ParseError(e) => write!(f, "{}", e), | |
} | |
} | |
} |
6d96be5
to
a0c8d74
Compare
Accept stringly types in typestate methods so that downstream implementations may depend on the typestate machines for URL parsing. This reduces a step for them and unifies our error handling for added internal complexity, which seems like the express purpose of the library. Create new ParseUrl error types in our state machines.
Removed gate is already inside a v2 feature module.
`use InternalSessionError::*;` is DRY.
Rather than link to the reqwest |
Blocking this until #522 is addressed |
Re: #513
Inspired by
reqwest::IntoUrl
After some consideration, I'm not sure if the goal really should be to remove
url
types from the public API. That crate is ancient and has a stable release cadence and conservative MSRV targets (1.63 even with the latest) that we can track.However, I still think the
IntoUrl
interface makes our typestate machines easier to work downstream with for the tradeoff of added complexity in our crate.In order to graduate from DRAFT I'd need new error types for
extract
functions that include aninto_url::Error
encapsulating variant. Before I do that work, I'm seeking a concept ack from @spacebear21 or otherwise a rejection of the idea, presumably on the grounds of too much complexity.Note, in payjoin-cli We're still validating URLs in configuration, and using the
url::Url
abstraction in function signatures makes more sense than becoming more loose for testing.The greatest advantage of this change may accrue to downstream FFI users, who I imagine use their native language's Url type and conversion to a stringly type that payjoin-ffi handles using IntoUrl rather than forcing them to use the
payjoin::Url
re-export and error handling.