Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/nornir

crates/mimir-driver/tests/fixture/b/src/lib.rs

//! fixture crate b 0.2.0 — calls into a (two versions), a trait impl, a method
//! call through a trait, a std call, extern "C" fns, a generic instantiated
//! twice, an `#[inline(always)]` fn.

use a::{Greet, Point};

pub struct Dog {
    pub name: String,
}

impl Greet for Dog {
    fn greet(&self) -> String {
        format!("woof {}", self.name)
    }
}

pub fn run(p: &Point, d: &Dog) -> i32 {
    let s = d.greet(); // static dispatch: resolves to b's impl method
    let g: &dyn Greet = d;
    let _ = g.greet(); // dyn dispatch: stays a's trait method
    let v = a::add(p.x, p.norm1()); // b -> a (0.1.0), field read, inherent method
    let v = a::add(v, 2); // a SECOND site of the same b -> a CALLS edge (count 2)
    let w = a_old::add(v, 1); // b -> a (0.0.9)
    let n = s.len(); // std (alloc) call
    let q = Point::new(1, 2);
    let r = unsafe { a::abs(w) }; // extern "C" border
    let pid = unsafe { a::getpid() }; // extern "C" border (stays an import)
    let t = a::tiny(r); // #[inline(always)]
    let i = a::ident(7u32).len() + a::ident("x").len(); // two mono instances
    t + n as i32 + q.y + i as i32 + (pid & 1)
}

/// names a fn as a VALUE: `Option::map` calls `a::tiny` through its generic
/// `F` — the body that names it reaches it
pub fn by_value(x: Option<i32>) -> Option<i32> {
    x.map(a::tiny)
}