1
Fork 0

Use FnOnce for slice_owned instead of Fn

This commit is contained in:
Maybe Waffle 2023-04-06 17:03:42 +00:00
parent 504c4c40e9
commit b6970d0e26
2 changed files with 3 additions and 3 deletions

View file

@ -37,7 +37,7 @@ pub struct DefaultMetadataLoader;
fn load_metadata_with( fn load_metadata_with(
path: &Path, path: &Path,
f: impl for<'a> Fn(&'a [u8]) -> Result<&'a [u8], String>, f: impl for<'a> FnOnce(&'a [u8]) -> Result<&'a [u8], String>,
) -> Result<MetadataRef, String> { ) -> Result<MetadataRef, String> {
let file = let file =
File::open(path).map_err(|e| format!("failed to open file '{}': {}", path.display(), e))?; File::open(path).map_err(|e| format!("failed to open file '{}': {}", path.display(), e))?;

View file

@ -59,7 +59,7 @@ pub struct OwnedSlice {
pub fn slice_owned<O, F>(owner: O, slicer: F) -> OwnedSlice pub fn slice_owned<O, F>(owner: O, slicer: F) -> OwnedSlice
where where
O: Send + Sync + 'static, O: Send + Sync + 'static,
F: Fn(&O) -> &[u8], F: FnOnce(&O) -> &[u8],
{ {
try_slice_owned(owner, |x| Ok::<_, !>(slicer(x))).into_ok() try_slice_owned(owner, |x| Ok::<_, !>(slicer(x))).into_ok()
} }
@ -70,7 +70,7 @@ where
pub fn try_slice_owned<O, F, E>(owner: O, slicer: F) -> Result<OwnedSlice, E> pub fn try_slice_owned<O, F, E>(owner: O, slicer: F) -> Result<OwnedSlice, E>
where where
O: Send + Sync + 'static, O: Send + Sync + 'static,
F: Fn(&O) -> Result<&[u8], E>, F: FnOnce(&O) -> Result<&[u8], E>,
{ {
// We box the owner of the bytes, so it doesn't move. // We box the owner of the bytes, so it doesn't move.
// //