mime icon indicating copy to clipboard operation
mime copied to clipboard

make mime partial eq to use in pattern match

Open dzmitry-lahoda opened this issue 4 years ago • 3 comments

error: to use a constant of type `Mime` in a pattern, `Mime` must be annotated with `#[derive(PartialEq, Eq)]`

dzmitry-lahoda avatar Feb 17 '21 08:02 dzmitry-lahoda

error: to use a constant of type `Mime` in a pattern, `Mime` must be annotated with `#[derive(PartialEq, Eq)]`
   --> libs\src\models.rs:345:13
    |
345 |             mime::APPLICATION_PDF => DownloadedFile::Pdf(file.content().to_owned()),

dzmitry-lahoda avatar Feb 17 '21 09:02 dzmitry-lahoda

This issue still stands and prevents pattern matching on constant types:

if let Some(mime::IMAGE_JPEG | mime::IMAGE_PNG) = beresp.get_content_type() {
    do_stuff();
}

The alternative to this code block following the pattern in the README would be:

if let Some(mime) = beresp.get_content_type() {
    match (mime.type_(), mime.subtype()) {
        (mime::IMAGE, mime::JPEG | mime::PNG) => do_stuff(),
        _ => {}
    }
}

kailan avatar Sep 13 '21 14:09 kailan

This would be resolved by #137.

kailan avatar Sep 13 '21 15:09 kailan