hyperium / http

Rust HTTP types
Apache License 2.0
1.16k stars 291 forks source link

[src/error.rs] pub ErrorKind #409

Open SamuelMarks opened 4 years ago

SamuelMarks commented 4 years ago

I'm confused how to percolate errors from http through my library.

I want to percolate up a http::uri::ErrorKind::InvalidFormat if .host() is None.

dekellum commented 4 years ago

The private http::error::ErrorKind shouldn't be in your way, since http::Error has is and get_ref for read access, and implements From<InvalidUri> (if "percolate" includes creating them). However, I see that http::uri::InvalidUri is itself opaque: not user constructable and only offers a description to read. Is that the real issue?

The prominent style here AFAICT, is to never expose a public enum. This unfortunately tends to leave users with only a description string, but #303 demonstrates willingness to improve usability in other ways. Perhaps kind-specific constructor functions and is_<kind>(&self) -> bool (e.g. is_invalid_format) methods could be added to InvalidUri?

SamuelMarks commented 4 years ago

@dekellum So how do I create a http::uri::InvalidUri in my codebase?