Mercurial > lbo > hg > lazycall
view examples/test_functions.rs @ 2:2b71ed370156
rustfmt
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Fri, 20 Nov 2020 23:26:10 +0100 |
parents | babb2f9cb5ad |
children |
line wrap: on
line source
use lazycall::{lazy, lazycall}; #[lazy] fn test_function_empty() -> i32 { 3 } struct TestStruct(i32); #[lazy] fn test_function_someargs(a: i32, b: usize, c: TestStruct) -> bool { a % 2 == 0 } #[lazy] fn test_function_onearg(a: i32) -> bool { a % 2 == 0 } impl TestStruct { #[lazy] fn test_receiving_func(&self, a: i32) -> bool { (self.0 + a) % 2 == 0 } } fn a_very_expensive_function() -> i32 { use std::thread; use std::time; thread::sleep(time::Duration::new(2, 0)); 32 } fn main() { println!("{}", test_function_onearg(a_very_expensive_function())); println!( "lazy: {}", lazycall!(test_function_onearg(a_very_expensive_function())) ); let mystruct = TestStruct(32); println!("{}", mystruct.test_receiving_func(33)); println!("lazy: {}", lazycall!(mystruct.test_receiving_func(33))); }