Preview Runtime Showcase

3. Foreign Rust References🔗

This chapter previews foreign Rust references backed by a live language-server lookup. Resolved references render a compact Rust source link and a grouped Rust code panel fetched from the location returned by rust-analyzer.

Definition3.1
XL∃∀Nused by 0

The Collatz step sends an even number to half of itself and an odd number to 3n + 1.

Rust code for Definition3.1
  • collatz_stepsource
    /// Return the next value in the Collatz orbit.
    pub fn collatz_step(n: u64) -> u64 {
        if n % 2 == 0 {
            n / 2
        } else {
            3 * n + 1
        }
    }
Definition3.2
XL∃∀Nused by 0

The bounded search version measures each orbit and checks a finite prefix of the Collatz conjecture.

Rust code for Definition3.2
  • collatz_total_stopping_timesource
    /// Count how long the Collatz orbit of `n` takes to reach `1`.
    pub fn collatz_total_stopping_time(mut n: u64) -> u64 {
        let mut steps = 0;
        while n > 1 {
            n = collatz_step(n);
            steps += 1;
        }
        steps
    }
  • collatz_holds_belowsource
    /// Check the Collatz conjecture by exhaustive search below a finite bound.
    pub fn collatz_holds_below(limit: u64) -> bool {
        for n in 1..=limit {
            if collatz_total_stopping_time(n) > 10_000 {
                return false;
            }
        }
        true
    }
Definition3.3
XL∃∀Nused by 0

Constants and statics live in Rust's value namespace, so the current synthetic lookup strategy resolves them like functions.

Rust code for Definition3.3
  • COLLATZ_LIMITsource
    /// Default finite bound used by the preview search.
    pub const COLLATZ_LIMIT: u64 = 10_000;
  • COLLATZ_STARTsource
    /// A familiar starting value with a long but finite Collatz orbit.
    pub static COLLATZ_START: u64 = 27;
Definition3.4
XL∃∀Nused by 0

A mixed attachment keeps the resolved reference and reports the missing one as a warning.

Rust code for Definition3.4
  • Resolvedcollatz_step
  • Unresolvedcollatz_typo: language server did not return a definition location
  • collatz_stepsource
    /// Return the next value in the Collatz orbit.
    pub fn collatz_step(n: u64) -> u64 {
        if n % 2 == 0 {
            n / 2
        } else {
            3 * n + 1
        }
    }
Definition3.5
XL∃∀Nused by 0

A completely missing Rust symbol produces an unresolved reference without a code panel.

Rust code for Definition3.5
  • Unresolvedmissing_collatz_symbol: language server did not return a definition location
Definition3.6
XL∃∀Nused by 0

These names exercise Rust's type namespace. They are included as a live preview of the current synthetic lookup shape, which is still optimized for value references.

Rust code for Definition3.6
  • CollatzRecordsource
    /// A small record for Collatz computations.
    pub struct CollatzRecord {
        pub start: u64,
        pub steps: u64,
    }
  • CollatzParitysource
    /// The parity branch selected by one Collatz step.
    pub enum CollatzParity {
        Even,
        Odd,
    }
  • CollatzMeasuresource
    /// A trait shape included to exercise Rust's type namespace.
    pub trait CollatzMeasure {
        fn measure(&self) -> u64;
    }
  • CollatzValuesource
    /// A type alias included to exercise Rust's type namespace.
    pub type CollatzValue = u64;