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
Consider a Port type for Uri::port() #173
Comments
You'd probably want to add a bunch of |
These would be better as |
No reason to not have both! |
@seanmonstar got a PR in progress for implementing struct Port<'a> {
bytes: &'a str,
} Is there any particular benefit to having struct Port {
port: u16,
}
impl Port {
fn from_bytes(bytes: &str) -> Option<Port>) {
u16::from_str(bytes).and_then(|p| Some(p.into())).ok()
}
fn to_string(&self) -> String { self.port.to_string() }
fn as_u16(&self) -> String { self.port } // Also impl From<u16> for Port {}
} |
The main reason would be to avoid parsing if not needed 🤷 |
@joshleeb people can already get the |
Do we want to pull out the valid port number, as a pub fn new(bytes: &'str) -> Option<Port<'a>> {
bytes
.rfind(":")
.and_then(|i| u16::from_str(bytes).ok())
.and_then(|_| Some(Port{ bytes }))
} Or do we just want to store the raw bytes, even if it's an invalid port number? |
Hm, yea, since the port isn't verified to be a valid |
Users may wish to access the port as a string, and not just an integer. We have the string already, so we could provide a newtype around it,
Port
, and a user can then get the bytes themselves, or just ask for the integer.This would be for both
Uri
andAuthority
. Probably introduced asport_part()
, deprecatingport()
to be replaced in 0.2.The text was updated successfully, but these errors were encountered: