Skip to main content

Rendered

Struct Rendered 

Source
pub struct Rendered {
    pub tokens: Vec<Token>,
}
Expand description

A line as tokens (whitespace included).

Fields§

§tokens: Vec<Token>

The tokens, in order.

Implementations§

Source§

impl Rendered

Source

pub fn text(&self) -> String

The line’s text.

Examples found in repository?
examples/listing.rs (line 52)
33fn main() {
34    let args: Vec<String> = std::env::args().collect();
35    let path = args
36        .get(1)
37        .expect("usage: listing FILE [ADDRESS [LINES] | --all]");
38    let data = std::fs::read(path).unwrap();
39    let image = Image::parse(&data).unwrap();
40    let db = Database::new(&image, Seeds::ALL).unwrap();
41    let references = Instant::now();
42    db.references();
43    let references = references.elapsed();
44    let before = resident_kib();
45    let start = Instant::now();
46    let listing = Listing::build(&db, &Options::default());
47    let built = start.elapsed();
48    let after = resident_kib();
49    match args.get(2).map(String::as_str) {
50        Some("--all") => {
51            for n in 0..listing.len() {
52                println!("{}", listing.render(&db, n).text());
53            }
54        }
55        Some(address) => {
56            let address = u64::from_str_radix(address.trim_start_matches("0x"), 16).unwrap();
57            let count: u64 = args.get(3).map_or(40, |n| n.parse().unwrap());
58            let first = listing.line_of(address);
59            // From the item's first line (its header and labels).
60            let head = listing.line(first).unwrap().address;
61            let mut n = first;
62            while n > 0 && listing.line(n - 1).is_some_and(|l| l.address == head) {
63                n -= 1;
64            }
65            for n in n..(n + count).min(listing.len()) {
66                println!("{}", listing.render(&db, n).text());
67            }
68        }
69        None => {
70            let render = Instant::now();
71            let (mut symbolised, mut instructions) = (0u64, 0u64);
72            for n in 0..listing.len() {
73                let rendered = listing.render(&db, n);
74                if listing.line(n).unwrap().kind == LineKind::Instruction {
75                    instructions += 1;
76                    symbolised += rendered
77                        .tokens
78                        .iter()
79                        .filter(|t| {
80                            matches!(
81                                t.role,
82                                Role::CodeName
83                                    | Role::DataName
84                                    | Role::ImportName
85                                    | Role::LocalName
86                            )
87                        })
88                        .count() as u64;
89                }
90            }
91            let stats = listing.stats();
92            println!(
93                "{path}: references {:.2} s; line space {:.3} s, RSS +{} MiB ({} MiB, peak {} MiB); \
94                 {} lines, {} instructions, {} data items, {} dummy names, {} string names; \
95                 rendering every line {:.2} s: {} operands symbolised in {} instructions",
96                references.as_secs_f64(),
97                built.as_secs_f64(),
98                after.saturating_sub(before) / 1024,
99                after / 1024,
100                status_kib("VmHWM:") / 1024,
101                stats.lines,
102                stats.instructions,
103                stats.data_items,
104                stats.dummy_names,
105                stats.string_names,
106                render.elapsed().as_secs_f64(),
107                symbolised,
108                instructions,
109            );
110        }
111    }
112}

Trait Implementations§

Source§

impl Clone for Rendered

Source§

fn clone(&self) -> Self

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 Rendered

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Rendered

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Rendered

Source§

impl PartialEq for Rendered

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Rendered

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> Same for T

Source§

type Output = T

Should always be Self
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.