Skip to content

Commit

Permalink
Fix building egui_extras without additional features
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Sep 13, 2023
1 parent d51f345 commit ceae934
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions crates/egui_extras/src/loaders/file_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,29 @@ impl BytesLoader for FileLoader {
.spawn({
let ctx = ctx.clone();
let cache = self.cache.clone();
let uri = uri.to_owned();
let _uri = uri.to_owned();
move || {
let result = match std::fs::read(&path) {
Ok(bytes) => Ok(File {
bytes: bytes.into(),
mime: mime_guess::from_path(&path)
Ok(bytes) => {
#[cfg(feature = "mime_guess")]
let mime = mime_guess::from_path(&path)
.first_raw()
.map(|v| v.to_owned()),
}),
.map(|v| v.to_owned());

#[cfg(not(feature = "mime_guess"))]
let mime = None;

Ok(File {
bytes: bytes.into(),
mime,
})
}
Err(err) => Err(err.to_string()),
};
let prev = cache.lock().insert(path, Poll::Ready(result));
assert!(matches!(prev, Some(Poll::Pending)));
ctx.request_repaint();
crate::log_trace!("finished loading {uri:?}");
crate::log_trace!("finished loading {_uri:?}");
}
})
.expect("failed to spawn thread");
Expand Down

0 comments on commit ceae934

Please sign in to comment.