yfunc_rust/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]

mod error;
mod ytime;
mod yuid;
mod func;
mod page;
mod ybytes;

pub use error::*;
pub use ytime::YTime;
pub use yuid::YUid;
pub use func::*;
pub use page::Page;
pub use ybytes::YBytes;
pub use yfunc_rust_macro::yfunc;

pub mod prelude {
    pub use crate::{yfunc, YRes, YError, Trace, err, ctx, INTERNAL_ERROR};
    pub use log::{debug, trace, info, warn, error};
}

#[cfg(test)]
mod tests {

    use super::*;

    #[test]
    fn err_works() {
        let x = 3; 
        let y = "test";
        println!("{:?}", err!());
        println!("{:?}", err!("something failed"));
        println!("{:?}", err!("something failed, x={}", 3));
        println!("{:?}", err!("SOME_ERROR": "something failed"));
        println!("{:?}", err!("SOME_ERROR": "something failed, x={}, y={}", x, y));
    }

    #[test]
    fn ctx_works() {
        let x = 3; 
        let y = "test";
        println!("{}", ctx!());
        println!("{}", ctx!("A -> B -> C"));
        println!("{}", ctx!(x));
        println!("{}", ctx!(y));
        println!("{}", ctx!(y, x));
        println!("{}", ctx!("A -> B -> C: D", x, y));
    }

    #[test]
    fn unique_works() {
        let list = vec!["123", "345", "123", "222"];
        println!("{:?}", list.unique())
    }

}