Use OwnedSlice
instead of owning_ref
This commit is contained in:
parent
689beda166
commit
c0ceefdfaf
6 changed files with 27 additions and 36 deletions
|
@ -13,8 +13,7 @@ use object::{
|
|||
use snap::write::FrameEncoder;
|
||||
|
||||
use rustc_data_structures::memmap::Mmap;
|
||||
use rustc_data_structures::owning_ref::OwningRef;
|
||||
use rustc_data_structures::rustc_erase_owner;
|
||||
use rustc_data_structures::owned_slice::try_slice_owned;
|
||||
use rustc_data_structures::sync::MetadataRef;
|
||||
use rustc_metadata::fs::METADATA_FILENAME;
|
||||
use rustc_metadata::EncodedMetadata;
|
||||
|
@ -38,14 +37,14 @@ pub struct DefaultMetadataLoader;
|
|||
|
||||
fn load_metadata_with(
|
||||
path: &Path,
|
||||
f: impl for<'a> FnOnce(&'a [u8]) -> Result<&'a [u8], String>,
|
||||
f: impl for<'a> Fn(&'a [u8]) -> Result<&'a [u8], String>,
|
||||
) -> Result<MetadataRef, String> {
|
||||
let file =
|
||||
File::open(path).map_err(|e| format!("failed to open file '{}': {}", path.display(), e))?;
|
||||
let data = unsafe { Mmap::map(file) }
|
||||
.map_err(|e| format!("failed to mmap file '{}': {}", path.display(), e))?;
|
||||
let metadata = OwningRef::new(data).try_map(f)?;
|
||||
return Ok(rustc_erase_owner!(metadata.map_owner_box()));
|
||||
|
||||
unsafe { Mmap::map(file) }
|
||||
.map_err(|e| format!("failed to mmap file '{}': {}", path.display(), e))
|
||||
.and_then(|mmap| try_slice_owned(mmap, |mmap| f(mmap)))
|
||||
}
|
||||
|
||||
impl MetadataLoader for DefaultMetadataLoader {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue