granit_parser/macros.rs
1//! Public macro for constructing [`Options`](crate::Options) without struct literal syntax.
2//!
3//! This macro keeps call sites ergonomic while allowing the option struct to gain fields without a
4//! breaking change.
5
6/// Construct [`Options`](crate::Options) from its defaults and a list of field assignments.
7///
8/// # Examples
9///
10/// ```rust
11/// let options = granit_parser::options! {
12/// max_buffered_comment_events: 64,
13/// emit_comments: false,
14/// simple_key_max_lookahead: 2048,
15/// };
16///
17/// assert_eq!(options.max_buffered_comment_events, 64);
18/// assert!(!options.emit_comments);
19/// assert_eq!(options.simple_key_max_lookahead, 2048);
20/// assert_eq!(options.flow_nesting_limit, 255);
21/// ```
22#[macro_export]
23macro_rules! options {
24 ($($field:ident : $value:expr),* $(,)?) => {{
25 let mut options = $crate::Options::default();
26 $(options.$field = $value;)*
27 options
28 }};
29}