-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Tracking Issue for addr_parse_ascii feature #101035
Comments
Bikeshedding: Usually |
Anything blocking an FCP for this feature? Very happy about more non-string APIs getting added |
I think I support what @niklasf has said above. Function names beginning with |
I have also come across need for this a lot, but not just for these types - almost everything we parse in std is strictly ASCII (e.g. numbers). If this is going to be a common thing, I am thinking that maybe we should have a separate trait like pub trait FromBytes: Sized {
type Err;
// Required method
fn from_bytes(s: &str) -> Result<Self, Self::Err>;
}
impl<T> FromStr for T where T: FromBytes { /* ... */ }
impl<[u8]> {
pub fn parse<F>(&self) -> Result<F, <F as FromStr>::Err>
where F: FromBytes,
} @BurntSushi I know you have had some ideas about improving ascii support in the language, any thoughts here? Edit: opened an ACP at rust-lang/libs-team#287 to discuss this further |
Parsing a network address "from bytes" usually implies that the bytes are used directly as the network address, which is a fixed-size and non-failable conversion (aka struct Ipv4Addr {
// already implemented as: impl From<[u8; 4]> for Ipv4Addr and IpAddr
fn from_bytes(bytes: [u8; 4]) -> Ipv4Addr;
}
struct Ipv6Addr {
// already implemented as: impl From<[u8; 16]> for Ipv6Addr and IpAddr
fn from_bytes(bytes: [u8; 16]) -> Ipv6Addr;
} |
Feature gate:
#![feature(addr_parse_ascii)]
This is a tracking issue for parsing network addresses (IP, Socket, etc) from a slice of bytes.
Internally the parser already works on bytes, this feature exposes publicly the ability to parse network address from a slice of bytes and therefor avoid the need to do utf8 validation in case one has only bytes.
Public API
Steps / History
Unresolved Questions
Footnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩
The text was updated successfully, but these errors were encountered: