Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loosen Fn trait bounds on fs::load_file #433

Open
sokorototo opened this issue May 11, 2024 · 0 comments
Open

Loosen Fn trait bounds on fs::load_file #433

sokorototo opened this issue May 11, 2024 · 0 comments

Comments

@sokorototo
Copy link

sokorototo commented May 11, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant