Skip to content

Commit

Permalink
Make loaders publix
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Sep 14, 2023
1 parent afe54e2 commit 8d7808f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 6 additions & 2 deletions crates/egui/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2018,7 +2018,10 @@ impl Context {
pub fn try_load_bytes(&self, uri: &str) -> load::BytesLoadResult {
crate::profile_function!();

for loader in self.loaders().bytes.lock().iter() {
let loaders = self.loaders();
let loaders = loaders.bytes.lock();

for loader in loaders.iter() {
match loader.load(self, uri) {
Err(load::LoadError::NotSupported) => continue,
result => return result,
Expand Down Expand Up @@ -2103,7 +2106,8 @@ impl Context {
Err(load::LoadError::NotSupported)
}

fn loaders(&self) -> Arc<Loaders> {
/// The loaders of bytes, images, and textures.
pub fn loaders(&self) -> Arc<Loaders> {
crate::profile_function!();
self.read(|this| this.loaders.clone())
}
Expand Down
5 changes: 3 additions & 2 deletions crates/egui/src/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub enum LoadError {
/// There are no image loaders installed.
NoImageLoaders,

/// This loader does not support this protocol or image format.
/// This loader does not support this schema, protocol or image format.
NotSupported,

/// A custom error message (e.g. "File not found: foo.png").
Expand Down Expand Up @@ -487,7 +487,8 @@ type ImageLoaderImpl = Arc<dyn ImageLoader + Send + Sync + 'static>;
type TextureLoaderImpl = Arc<dyn TextureLoader + Send + Sync + 'static>;

#[derive(Clone)]
pub(crate) struct Loaders {
/// The loaders of bytes, images, and textures.
pub struct Loaders {
pub include: Arc<DefaultBytesLoader>,
pub bytes: Mutex<Vec<BytesLoaderImpl>>,
pub image: Mutex<Vec<ImageLoaderImpl>>,
Expand Down

0 comments on commit 8d7808f

Please sign in to comment.