Skip to content

Loosen Fn trait bounds on fs::load_file #433

@sokorototo

Description

@sokorototo

miniquad/src/fs.rs

Lines 31 to 44 in 8a15083

/// Filesystem path on desktops or HTTP URL in WASM
pub fn load_file<F: Fn(Response) + 'static>(path: &str, on_loaded: F) {
#[cfg(target_arch = "wasm32")]
wasm::load_file(path, on_loaded);
#[cfg(target_os = "android")]
load_file_android(path, on_loaded);
#[cfg(target_os = "ios")]
ios::load_file(path, on_loaded);
#[cfg(not(any(target_arch = "wasm32", target_os = "android", target_os = "ios")))]
load_file_desktop(path, on_loaded);
}

fs::load_file is only expected to ever call its closure once, and thus only needs to implement FnOnce. Fn allows for the function to be called multiple times, and thus can't drop any wrapped values during its invocation. FnOnce is easier to implement and thus makes load_file easier to use.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions