rust read 100G large file

rust 复制代码
/**

 * Main function that demonstrates memory mapping a large file and accessing its contents.

 *

 * This function:

 * 1. Opens a large virtual disk file (ext4.vhdx)

 * 2. Creates a memory mapping of the file

 * 3. Accesses the mapped content

 * 4. Prints the memory address of the content and its length

 *

 * Returns:

 *   Result<(), Box<dyn std::error::Error>> - Ok on success, or an error boxed as a trait object

 */

fn main() -> Result<(), Box<dyn std::error::Error>> {

    use std::fs::File;

    use doe::memory_address;

    use memmap2::Mmap;

   

    // Open the virtual disk file in read-only mode

    let file = File::open("D:/arch_linux/ext4.vhdx")?;

   

    // Create a memory map of the entire file (unsafe due to potential undefined behavior)

    let mmap = unsafe { Mmap::map(&file)? };

  


    // Get a slice reference to the entire mapped memory

    let content = &mmap[..];

 

    // Print the memory address and length of the mapped content

    println!("memory_address:{:?}", memory_address!(content));

    println!("len:{}", content.len());

   

    Ok(())

}
相关推荐
盒马盒马15 小时前
Rust:内部可变性 & 型变
开发语言·后端·rust
云水木石18 小时前
Rust 语言开发的 Linux 桌面来了
linux·运维·开发语言·后端·rust
Source.Liu19 小时前
【time-rs】解释://! Invalid format description(error/invalid_format_description.rs)
rust·time
fegggye19 小时前
创建一个rust写的python库[signatures和错误处理]
开发语言·python·rust
Source.Liu19 小时前
【time-rs】解释://! Indeterminate offset(error/indeterminate_offset.rs)
rust·time
福大大架构师每日一题19 小时前
rust 1.92.0 更新详解:语言特性增强、编译器优化与全新稳定API
java·javascript·rust
分布式存储与RustFS1 天前
MinIO替代方案精选:RustFS深度评测与选型指南
人工智能·rust·开源项目·对象存储·minio·企业存储·rustfs
JPX-NO1 天前
使用cargo-generate自定义创建项目模板
rust·mvc
JPX-NO1 天前
Rust Rocket Web 应用项目结构详解(MVC 风格)
rust·mvc·rocket
Source.Liu2 天前
【time-rs】DifferentVariant 错误类型详解(error/different_variant.rs)
rust·time