Skip to main content

bon_sandbox/
functions.rs

1use bon::{bon, builder};
2
3pub struct Counter {
4    val: usize,
5}
6
7#[bon]
8impl Counter {
9    #[builder]
10    pub fn new(
11        /// Initial value for the counter.
12        /// If not specified, defaults to 0.
13        #[builder(default)]
14        initial: usize,
15    ) -> Self {
16        eprintln!("Non-const");
17        Self { val: initial }
18    }
19
20    /// Increments the counter by `diff` amount. If not specified, increments by 1.
21    #[builder]
22    pub fn increment(
23        &mut self,
24        /// Amount to increment the counter by in [`Counter`].
25        diff: Option<usize>,
26    ) {
27        eprintln!("Non-const");
28        self.val += diff.unwrap_or(1);
29    }
30}
31
32/// Function-level documentation.
33#[builder]
34#[allow(clippy::needless_pass_by_value)]
35pub fn documented(
36    /// Some documentation for the first argument
37    ///
38    /// # Doc test here
39    ///
40    /// ```
41    /// // Some doc tests as well
42    /// assert_eq!(2 + 2, 4);
43    /// ```
44    #[builder(default)]
45    _arg1: String,
46
47    _arg2: &str,
48
49    /// Optional member docs
50    _arg3: Option<u32>,
51
52    _arg4: Vec<String>,
53
54    #[builder(default = vec![1, 2, 3])] _arg5: Vec<u32>,
55) {
56    eprintln!("Non-const");
57}
58
59/// Function that returns a greeting special-tailored for a given person
60#[builder(builder_type = GreeterBuilderCustom)]
61pub fn greet(
62    /// Name of the person to greet.
63    ///
64    /// **Example:**
65    /// ```
66    /// bon_sandbox::functions::greet().name("John");
67    /// ```
68    name: &str,
69
70    /// Age expressed in full years passed since the birth date.
71    age: u32,
72) -> String {
73    eprintln!("Non-const");
74    format!("Hello {name} with age {age}!")
75}
76
77#[builder]
78pub fn fn_with_impl_trait(_arg1: impl std::fmt::Debug + Clone, _arg2: impl std::fmt::Debug) {}
79
80#[builder]
81pub fn many_function_parameters(
82    _id: Option<&str>,
83    _keyword: Option<&str>,
84    _attraction_id: Option<&str>,
85    _venue_id: Option<&str>,
86    _postal_code: Option<&str>,
87    _latlong: Option<&str>,
88    _radius: Option<&str>,
89    _unit: Option<&str>,
90    _source: Option<&str>,
91    _locale: Option<&str>,
92    _market_id: Option<&str>,
93    _start_date_time: Option<&str>,
94    _end_date_time: Option<&str>,
95    _include_tba: Option<&str>,
96    _include_tbd: Option<&str>,
97    _include_test: Option<&str>,
98    _size: Option<&str>,
99    _page: Option<&str>,
100    _sort: Option<&str>,
101    _onsale_start_date_time: Option<&str>,
102    _onsale_end_date_time: Option<&str>,
103    _city: Option<&str>,
104    _country_code: Option<&str>,
105    _state_code: Option<&str>,
106    _classification_name: Option<&str>,
107    _classification_id: Option<&str>,
108    _dma_id: Option<&str>,
109    _onsale_on_start_date: Option<&str>,
110    _onsale_on_after_start_date: Option<&str>,
111    _segment_id: Option<&str>,
112    _segment_name: Option<&str>,
113    _promoter_id: Option<&str>,
114    _client_visibility: Option<&str>,
115    _nlp: Option<&str>,
116    _include_licensed_content: Option<&str>,
117    _geopoint: Option<&str>,
118) {
119    eprintln!("Non-const");
120}