pub struct Disassembly { /* private fields */ }Expand description
The outcome of parsing one class-file input.
A complete result contains a Class. Best-effort recovery returns a partial result when
only the class-file header was available; callers can inspect Self::version and
Self::diagnostics in that case.
Implementations§
Source§impl Disassembly
impl Disassembly
Sourcepub fn version(&self) -> ClassVersion
pub fn version(&self) -> ClassVersion
Returns the class-file version read from the input header.
This is available for both complete and partial results.
Examples found in repository?
examples/disassemble.rs (line 25)
17fn run() -> Result<ExitCode, String> {
18 let path = class_path()?;
19 let file =
20 File::open(&path).map_err(|error| format!("could not open {}: {error}", path.display()))?;
21 let disassembly = Disassembler::default()
22 .parse_reader(file)
23 .map_err(|error| format!("could not parse {}: {error}", path.display()))?;
24
25 let version = disassembly.version();
26 let Some(class) = disassembly.class() else {
27 println!(
28 "partial class file v{}.{}",
29 version.major(),
30 version.minor()
31 );
32 for diagnostic in disassembly.diagnostics() {
33 print_diagnostic(diagnostic);
34 }
35 return Ok(ExitCode::from(2));
36 };
37
38 let output = FerroFormatter
39 .format(class)
40 .map_err(|error| format!("could not format {}: {error}", path.display()))?;
41 print!("{output}");
42
43 Ok(ExitCode::SUCCESS)
44}Sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
Returns true when a complete Class model is available.
Sourcepub fn class(&self) -> Option<&Class>
pub fn class(&self) -> Option<&Class>
Returns the complete parsed class, if decoding finished successfully.
Returns None for a best-effort partial result.
Examples found in repository?
examples/disassemble.rs (line 26)
17fn run() -> Result<ExitCode, String> {
18 let path = class_path()?;
19 let file =
20 File::open(&path).map_err(|error| format!("could not open {}: {error}", path.display()))?;
21 let disassembly = Disassembler::default()
22 .parse_reader(file)
23 .map_err(|error| format!("could not parse {}: {error}", path.display()))?;
24
25 let version = disassembly.version();
26 let Some(class) = disassembly.class() else {
27 println!(
28 "partial class file v{}.{}",
29 version.major(),
30 version.minor()
31 );
32 for diagnostic in disassembly.diagnostics() {
33 print_diagnostic(diagnostic);
34 }
35 return Ok(ExitCode::from(2));
36 };
37
38 let output = FerroFormatter
39 .format(class)
40 .map_err(|error| format!("could not format {}: {error}", path.display()))?;
41 print!("{output}");
42
43 Ok(ExitCode::SUCCESS)
44}Sourcepub fn diagnostics(&self) -> &[Diagnostic]
pub fn diagnostics(&self) -> &[Diagnostic]
Returns diagnostics collected during best-effort recovery.
Complete results currently return an empty slice.
Examples found in repository?
examples/disassemble.rs (line 32)
17fn run() -> Result<ExitCode, String> {
18 let path = class_path()?;
19 let file =
20 File::open(&path).map_err(|error| format!("could not open {}: {error}", path.display()))?;
21 let disassembly = Disassembler::default()
22 .parse_reader(file)
23 .map_err(|error| format!("could not parse {}: {error}", path.display()))?;
24
25 let version = disassembly.version();
26 let Some(class) = disassembly.class() else {
27 println!(
28 "partial class file v{}.{}",
29 version.major(),
30 version.minor()
31 );
32 for diagnostic in disassembly.diagnostics() {
33 print_diagnostic(diagnostic);
34 }
35 return Ok(ExitCode::from(2));
36 };
37
38 let output = FerroFormatter
39 .format(class)
40 .map_err(|error| format!("could not format {}: {error}", path.display()))?;
41 print!("{output}");
42
43 Ok(ExitCode::SUCCESS)
44}Trait Implementations§
Source§impl Clone for Disassembly
impl Clone for Disassembly
Source§fn clone(&self) -> Disassembly
fn clone(&self) -> Disassembly
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for Disassembly
impl RefUnwindSafe for Disassembly
impl Send for Disassembly
impl Sync for Disassembly
impl Unpin for Disassembly
impl UnsafeUnpin for Disassembly
impl UnwindSafe for Disassembly
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more