mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 22:00:03 -04:00
* Closes #4654 * Related #4667 * [x] I have followed the instructions in the PR template This PR avoids materializing the contents of a file that was dragged into an egui application on the web. It does so by storing the `web_sys::File` handle directly on WASM. This breaks the existing API of `DroppedFile` on the web, because there is no way to retrieve the bytes synchronously form a `DroppedFile` anymore, forcing handling call sites to become asynchronous. The native API remains the same. --------- Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
23 lines
425 B
Rust
23 lines
425 B
Rust
use std::path::{Path, PathBuf};
|
|
|
|
#[derive(Debug)]
|
|
pub(crate) struct NativeFile {
|
|
path: PathBuf,
|
|
}
|
|
|
|
impl From<PathBuf> for NativeFile {
|
|
fn from(path: PathBuf) -> Self {
|
|
Self { path }
|
|
}
|
|
}
|
|
|
|
impl egui::DroppedFile for NativeFile {
|
|
fn path(&self) -> &Path {
|
|
&self.path
|
|
}
|
|
|
|
fn bytes(&self) -> Result<Vec<u8>, String> {
|
|
std::fs::read(&self.path).map_err(|err| err.to_string())
|
|
}
|
|
}
|