From e0ba85ea1b7176b039d229c1e4d00c2ea37fcf7c Mon Sep 17 00:00:00 2001 From: Christian Kruse Date: Tue, 27 Dec 2022 08:22:10 +0100 Subject: [PATCH] if magic is disabled `self.magic` is not available and thus compilation fails with `if cfg!()` construct --- src/mastodon.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/mastodon.rs b/src/mastodon.rs index dc585e2..9f58ab3 100644 --- a/src/mastodon.rs +++ b/src/mastodon.rs @@ -401,13 +401,14 @@ impl Mastodon { use std::io::Read; let path = path.as_ref(); - let mime = if cfg!(feature = "magic") { - self.magic.file(path).ok() - // if it doesn't work, it's no big deal. The server will look at - // the filepath if this isn't here and things should still work. - } else { - None - }; + + // if it doesn't work, it's no big deal. The server will look at + // the filepath if this isn't here and things should still work. + #[cfg(feature = "magic")] + let mime = self.magic.file(path).ok(); + #[cfg(not(feature = "magic"))] + let mime: Option = None; + match std::fs::File::open(path) { Ok(mut file) => { let mut data = if let Ok(metadata) = file.metadata() {