Crates.io | kexplain |
lib.rs | kexplain |
version | 0.1.0 |
source | src |
created_at | 2022-06-02 08:33:12.865977 |
updated_at | 2022-06-02 08:33:12.865977 |
description | Derive explanations for functions by 'showing the work' for things like math |
homepage | https://github.com/norcalli/kexplain/ |
repository | https://github.com/norcalli/kexplain/ |
max_upload_size | |
id | 598735 |
size | 9,814 |
use kexplain::explain;
#[explain]
fn foo(a: u32, b: f64) -> u32 {
let _x = a * b as u32;
#[no_expr]
let x = a * b as u32;
#[skip]
let _y = a * b as u32;
x * 3
}
struct Foo;
impl Foo {
#[explain]
fn bar(&self, a: u32, b: f64) -> u32 {
let _x = a * b as u32;
#[no_expr]
let x = a * b as u32;
#[skip]
let _y = a * b as u32;
x * 3
}
}
fn main() {
assert_eq!(6, foo(1, 2.));
assert_eq!(6, foo_explain(1, 2., |name, expr, value| {
println!("{name} {expr:?} {value}");
}));
assert_eq!(6, Foo.bar(1, 2.));
assert_eq!(6, Foo.bar_explain(1, 2., |name, expr, value| {
println!("{name} {expr:?} {value}");
}));
}
Example stdout:
STDOUT:
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
a None 1
b None 2
_x Some("a * b as u32") 2
x None 2
None 6
a None 1
b None 2
_x Some("a * b as u32") 2
x None 2
None 6
┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈