optargs/lib.rs
1use optargs_macro;
2
3/// Optional arguments for functions!
4/// Add optfn on top of any function and then you can call the funtion with optional arguments.
5///
6/// Note that this still obeys traditional macro_rules, so you can only use the macro *after* declaration or import it from "crate".
7///
8///
9/// ```ignore
10/// #[optargs::optfn]
11/// pub fn plot(
12/// x: Vec<i32>,
13/// y: Option<Vec<i32>>,
14/// title: Option<&str>,
15/// xlabel: Option<&str>,
16/// ylabel: Option<&str>,
17/// legend: Option<bool>
18/// ) {}
19///
20/// // can now call it with optional arguments
21/// plot!(
22/// x: vec![1,2,3],
23/// y: vec![1,2,3],
24/// title: "Awesome plot",
25/// xlabel: "x axis",
26/// ylabel: "y axis"
27/// );
28/// ```
29pub use optargs_macro::optfn;
30
31/// Flexible struct builder with optional arguments
32/// Derive OptStruct for your structs and then call the Struct's name as a macro to build it, eliding optionals.
33///
34/// Note that this still obeys traditional macro_rules, so you can only use the macro *after* declaration or import it from "crate".
35///
36/// ```rust
37/// #[derive(optargs::OptStruct)]
38/// pub struct Scatter {
39/// x: Vec<i32>,
40/// y: Option<Vec<i32>>,
41/// title: Option<&str>,
42/// xlabel: Option<&str>,
43/// ylabel: Option<&str>,
44/// legend: Option<bool>
45/// }
46///
47/// let plot = Scatter!{
48/// x: vec![1,2,3],
49/// legend: true
50/// };
51/// ```
52pub use optargs_macro::OptStruct;