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
Method naming #43
Comments
Yeah, this is something I haven't been happy with myself, accumulating different functions that do slightly different things as multiple people had problems with different parts of the existing API. This is what I'm thinking for 2.0:
I'd also like to address #28 in this release by having a function that returns slices, but I dunno if that should just be |
Is there no way to reduce the number of combinations?
|
I originally created this crate out of a need in the client API in I don't think functions taking paths is too misleading; it's extremely unidiomatic to hide disk access behind such an unassuming function that doesn't even return I was considering a struct/method chain approach but I felt it was slightly more complex than this crate needs. I'd rather keep the API flat. |
I don't know about uploads, but on the server side it's better to not send a Content-Type at all -- I mentioned this in my PR, so I'm not going into that again.
Unless you expect the function to "guess" when there's an I/O error.
Well, it's one solution to the O(N * M) proliferation of functions. It could also solve #28. It's okay if you don't like it -- the |
Conversely, in
This is where my choice of fallback came from. Since it doesn't work as well for the server-side I'm fine dropping it. You touched on this already, but what about /// The possible `Mime` values for the given path/extension or empty otherwise.
pub struct MimeGuess(pub &'static [Mime]);
impl MimeGuess {
// all of these return the first value in the slice or their respective fallback
// clones should be cheap if the `Mime` is compile-time constructed
pub fn or_text_plain(&self) -> Mime { ... }
pub fn or_octet_stream(&self) -> Mime { ... }
pub fn or(&self, mime: Mime) -> Mime { ... }
pub fn or_else(&self, or_else: impl FnOnce() -> Mime) -> Mime { ... }
// bikeshed `to_opt`
pub fn to_mime(&self) -> Option<Mime> { ... }
// bikeshed `to_opt_str`
pub fn to_str(&self) -> Option<&'static str> { ... }
} The new release of What about just |
Sorry, I kinda' dropped the ball here. Yeah, it sounds great. One use case for strings I can think of is interop with the http crate. |
The new API of |
Continuing from #38.
Right now there are some
get_mime_type
andguess_mime_type
methods, and the difference between them is that the former take an extension and the latter take aPath
. There's alsomime_str_for_path_ext
from #38, which could have been calledguess_mime_type_str
.Additionally,
{guess,get}_mime_type
returnMime
{guess,get}_mime_type_opt
returnOption<Mime>
get_mime_type_str
andmime_str_for_path_ext
returnOption<&'static str>
To be honest, this is a bit of a mess. Can we settle on a naming convention that's more regular before releasing
2.0
(#42)?The text was updated successfully, but these errors were encountered: