Skip to main content

Disassembly

Struct Disassembly 

Source
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

Source

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}
Source

pub fn is_complete(&self) -> bool

Returns true when a complete Class model is available.

Source

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}
Source

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

Source§

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)

Performs copy-assignment from source. Read more
Source§

impl Debug for Disassembly

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.