]>
git.proxmox.com Git - rustc.git/blob - vendor/object/src/lib.rs
3 //! The `object` crate provides a unified interface to working with object files
4 //! across platforms. It supports reading object files and executable files,
5 //! and writing object files.
7 //! ## Raw struct definitions
9 //! Raw structs are defined for: [ELF](elf), [Mach-O](macho), [PE/COFF](pe), [archive].
10 //! Types and traits for zerocopy support are defined in [pod] and [endian].
12 //! ## Unified read API
14 //! The [read::Object] trait defines the unified interace. This trait is implemented
15 //! by [read::File], which allows reading any file format, as well as implementations
16 //! for each file format: [ELF](read::elf::ElfFile), [Mach-O](read::macho::MachOFile),
17 //! [COFF](read::coff::CoffFile), [PE](read::pe::PeFile), [Wasm](read::wasm::WasmFile).
19 //! ## Low level read API
21 //! In addition to the unified read API, the various `read` modules define helpers that
22 //! operate on the raw structs. These also provide traits that abstract over the differences
23 //! between 32-bit and 64-bit versions of the file format.
25 //! ## Unified write API
27 //! [write::Object] allows building an object and then writing it out.
29 //! ## Example for unified read API
31 //! use object::{Object, ObjectSection};
32 //! use std::error::Error;
35 //! /// Reads a file and displays the content of the ".boot" section.
36 //! fn main() -> Result<(), Box<dyn Error>> {
37 //! let bin_data = fs::read("./multiboot2-binary.elf")?;
38 //! let obj_file = object::File::parse(&*bin_data)?;
39 //! if let Some(section) = obj_file.section_by_name(".boot") {
40 //! println!("{:#x?}", section.data()?);
42 //! eprintln!("section not available");
48 #![deny(missing_docs)]
49 #![deny(missing_debug_implementations)]
52 #![allow(clippy::collapsible_if)]
53 #![allow(clippy::comparison_chain)]
54 #![allow(clippy::match_like_matches_macro)]
55 #![allow(clippy::single_match)]
56 #![allow(clippy::type_complexity)]
57 // Occurs due to fallible iteration.
58 #![allow(clippy::should_implement_trait)]
59 // Unit errors are converted to other types by callers.
60 #![allow(clippy::result_unit_err)]
62 #![allow(clippy::transmute_ptr_to_ptr)]
64 #[cfg(feature = "cargo-all")]
65 compile_error
!("'--all-features' is not supported; use '--features all' instead");
67 #[cfg(feature = "read_core")]
68 #[allow(unused_imports)]
72 #[cfg(feature = "std")]
73 #[allow(unused_imports)]
88 #[cfg(feature = "read_core")]
90 #[cfg(feature = "read_core")]
93 #[cfg(feature = "write_core")]
96 #[cfg(feature = "archive")]
98 #[cfg(feature = "elf")]
100 #[cfg(feature = "macho")]
102 #[cfg(any(feature = "coff", feature = "pe"))]