]> git.proxmox.com Git - rustc.git/blobdiff - vendor/object/README.md
New upstream version 1.55.0+dfsg1
[rustc.git] / vendor / object / README.md
index e79f6e4728243bdeef52b4e57f03fc82f810a955..b6c753c3c0b3561b23304203de7865899b2f7907 100644 (file)
@@ -13,6 +13,25 @@ For reading files, it provides multiple levels of support:
 
 Supported file formats: ELF, Mach-O, Windows PE/COFF, Wasm, and Unix archive.
 
+## Example for unified read API
+```rust
+use object::{Object, ObjectSection};
+use std::error::Error;
+use std::fs;
+
+/// Reads a file and displays the content of the ".boot" section.
+fn main() -> Result<(), Box<dyn Error>> {
+  let bin_data = fs::read("./multiboot2-binary.elf")?;
+  let obj_file = object::File::parse(&*bin_data)?;
+  if let Some(section) = obj_file.section_by_name(".boot") {
+    println!("{:#x?}", section.data()?);
+  } else {
+    eprintln!("section not available");
+  }
+  Ok(())
+}
+```
+
 ## License
 
 Licensed under either of