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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
use super::enums::BinaryArch;
use serde::Serialize;
/// Struct corresponding to the `events -> app` key in the BugSnag
/// error-reporting API payload.
///
/// ```
/// use lemon_bugsnag_rs::error::payload::events::App;
///
/// let app = App::default();
/// ```
#[derive(Clone, Debug, Default, Serialize, Eq, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct App {
/// A unique ID for the application reporting the error.
pub id: Option<String>,
/// The version of the application which generated the error.
pub version: Option<String>,
/// The application's version code. Android only.
pub version_code: Option<u16>,
/// The bundle version of the application. MacOS, iOS, and tvOS only.
pub bundle_version: Option<String>,
/// A unique code bundle identifier. Mobile only.
pub code_bundle_id: Option<String>,
/// A build ID for the application which is reporting the error.
pub build_uuid: Option<String>,
/// The release stage for the application. Defaults to `production`.
pub release_stage: Option<String>,
/// Used to identify the type of application or frameworks used by the
/// applicaation. For instance, "Rust with NAB BugSnag RS."
#[serde(rename(serialize = "type"))]
pub app_type: Option<String>,
/// A vector of strings representing UUIDs from a debug symbols file.
pub dsym_uuids: Option<Vec<String>>,
/// How long the app was running before encountering the error(s) being
/// reported. Specified in milliseconds.
pub duration: Option<i64>,
/// How long the applications has been in the foreground of the device it
/// is running on.
pub duration_in_foreground: Option<i64>,
/// Whether or not the application was in the foreground when the error
/// occurred.
pub in_foreground: Option<bool>,
/// Whether or not the application was still launching when the error
/// occurred.
pub is_launching: Option<bool>,
/// A variant of the [BinaryArch] enum specifying the architecture
/// of the application which generated the error(s) being reported.
pub binary_arch: Option<BinaryArch>,
/// Whether or not the application was running on the Rosetta emulator
/// for MacIntosh when the error occurred.
pub running_on_rosetta: Option<bool>,
}
#[cfg_attr(docsrs, doc(cfg(feature = "optional-builders")))]
#[cfg(feature = "optional-builders")]
impl App {
/// Retrieve an [AppBuilder].
///
/// ```
/// use lemon_bugsnag_rs::error::payload::events::App;
///
/// let mut ab = App::builder();
/// ```
pub fn builder() -> AppBuilder {
AppBuilder { app: App::default() }
}
}
/// Builder used to generate an [App] struct.
///
/// ```
/// use lemon_bugsnag_rs::error::payload::events::App;
///
/// // Generally, you get the builder this way, rather than creating an
/// // AppBuilder struct manually.
/// let ab = App::builder();
/// ```
#[cfg_attr(docsrs, doc(cfg(feature = "optional-builders")))]
#[cfg(feature = "optional-builders")]
pub struct AppBuilder {
app: App,
}
#[cfg_attr(docsrs, doc(cfg(feature = "optional-builders")))]
#[cfg(feature = "optional-builders")]
impl AppBuilder {
/// Set the ID field of the App struct.
///
/// ```
/// use lemon_bugsnag_rs::error::payload::events::App;
///
/// let mut ab = App::builder();
///
/// // Give the ID a value.
/// ab.set_id("lemon-bugsnag-rs-doctest-set-id");
///
/// // Unset the ID.
/// ab.set_id(None);
/// ```
pub fn set_id<'a>(&mut self, id: impl Into<Option<&'a str>>) -> &mut Self {
self.app.id = id.into().map(move |item| item.into());
self
}
/// Set the version field of the App struct.
///
/// ```
/// use lemon_bugsnag_rs::error::payload::events::App;
///
/// let mut ab = App::builder();
///
/// // Give the version a value.
/// ab.set_version("0.0.2-alpha");
///
/// // Unset the version.
/// ab.set_version(None);
/// ```
pub fn set_version<'a>(
&mut self,
version: impl Into<Option<&'a str>>,
) -> &mut Self {
self.app.version = version.into().map(|item| item.into());
self
}
/// Set the version_code field of the App struct.
///
/// ```
/// use lemon_bugsnag_rs::error::payload::events::App;
///
/// let mut ab = App::builder();
///
/// // Give the version_code a value.
/// ab.set_version_code(256);
///
/// // Unset the version_code.
/// ab.set_version_code(None);
/// ```
pub fn set_version_code(
&mut self,
version_code: impl Into<Option<u16>>,
) -> &mut Self {
self.app.version_code = version_code.into();
self
}
/// Set the bundle_version field of the App struct.
///
/// ```
/// use lemon_bugsnag_rs::error::payload::events::App;
///
/// let mut ab = App::builder();
///
/// // Give the bundle_version a value.
/// ab.set_bundle_version("4.4.2");
///
/// // Unset the bundle_version.
/// ab.set_bundle_version(None);
/// ```
pub fn set_bundle_version<'a>(
&mut self,
bundle_version: impl Into<Option<&'a str>>,
) -> &mut Self {
self.app.bundle_version = bundle_version.into().map(|item| item.into());
self
}
/// Set the code_bundle_id field of the App struct.
///
/// ```
/// use lemon_bugsnag_rs::error::payload::events::App;
///
/// let mut ab = App::builder();
///
/// // Give the code_bundle_id a value.
/// ab.set_code_bundle_id("4.4.2");
///
/// // Unset the code_bundle_id.
/// ab.set_code_bundle_id(None);
/// ```
pub fn set_code_bundle_id<'a>(
&mut self,
code_bundle_id: impl Into<Option<&'a str>>,
) -> &mut Self {
self.app.code_bundle_id = code_bundle_id.into().map(|item| item.into());
self
}
/// Set the build_uuid field of the App struct.
///
/// ```
/// use lemon_bugsnag_rs::error::payload::events::App;
///
/// let mut ab = App::builder();
///
/// // Give the build_uuid a value.
/// ab.set_build_uuid("lemon-bugsnag-rs-224b");
///
/// // Unset the build_uuid.
/// ab.set_build_uuid(None);
/// ```
pub fn set_build_uuid<'a>(
&mut self,
build_uuid: impl Into<Option<&'a str>>,
) -> &mut Self {
self.app.build_uuid = build_uuid.into().map(|item| item.into());
self
}
/// Set the release_stage field of the App struct.
///
/// ```
/// use lemon_bugsnag_rs::error::payload::events::App;
///
/// let mut ab = App::builder();
///
/// // Give the release_stage a value.
/// ab.set_release_stage("dev");
///
/// // Unset the release_stage.
/// ab.set_release_stage(None);
/// ```
pub fn set_release_stage<'a>(
&mut self,
release_stage: impl Into<Option<&'a str>>,
) -> &mut Self {
self.app.release_stage = release_stage.into().map(|item| item.into());
self
}
/// Set the app_type field of the App struct.
///
/// ```
/// use lemon_bugsnag_rs::error::payload::events::App;
///
/// let mut ab = App::builder();
///
/// // Give the app_type a value.
/// ab.set_app_type("Rust + Reqwest + Ureq + BugSnag");
///
/// // Unset the app_type.
/// ab.set_app_type(None);
/// ```
pub fn set_app_type<'a>(
&mut self,
app_type: impl Into<Option<&'a str>>,
) -> &mut Self {
self.app.app_type = app_type.into().map(|item| item.into());
self
}
/// Set the dsym_uuids field of the App struct.
///
/// ```
/// use lemon_bugsnag_rs::error::payload::events::App;
///
/// let mut ab = App::builder();
///
/// // Give the dsym_uuids a value.
/// ab.set_dsym_uuids([
/// "03b1d975-166c-465e-b590-ba3b4efd3ead".to_string()
/// , "324589e5-9345-4873-a6c7-76c7b2fb6fad".to_string()
/// , "f097d96a-2914-4cdf-b9ce-79fc071b8b38".to_string()
/// , "025fea84-972a-456a-9868-115cc19440b5".to_string()
/// ].to_vec());
///
/// // Unset the dsym_uuids.
/// ab.set_dsym_uuids(None);
/// ```
pub fn set_dsym_uuids<'a>(
&mut self,
dsym_uuids: impl Into<Option<Vec<String>>>,
) -> &mut Self {
self.app.dsym_uuids = dsym_uuids.into();
self
}
/// Set the duration field of the App struct.
///
/// ```
/// use lemon_bugsnag_rs::error::payload::events::App;
///
/// let mut ab = App::builder();
///
/// // Give the duration a value.
/// ab.set_duration(32000);
///
/// // Unset the duration.
/// ab.set_duration(None);
/// ```
pub fn set_duration(
&mut self,
duration: impl Into<Option<i64>>,
) -> &mut Self {
self.app.duration = duration.into();
self
}
/// Set the duration_in_foreground field of the App struct.
///
/// ```
/// use lemon_bugsnag_rs::error::payload::events::App;
///
/// let mut ab = App::builder();
///
/// // Give the duration_in_foreground a value.
/// ab.set_duration_in_foreground(24000);
///
/// // Unset the duration_in_foreground.
/// ab.set_duration_in_foreground(None);
/// ```
pub fn set_duration_in_foreground(
&mut self,
duration_in_foreground: impl Into<Option<i64>>,
) -> &mut Self {
self.app.duration_in_foreground = duration_in_foreground.into();
self
}
/// Set the in_foreground field of the App struct.
///
/// ```
/// use lemon_bugsnag_rs::error::payload::events::App;
///
/// let mut ab = App::builder();
///
/// // Give the in_foreground a value.
/// ab.set_in_foreground(false);
///
/// // Unset the in_foreground.
/// ab.set_in_foreground(None);
/// ```
pub fn set_in_foreground(
&mut self,
in_foreground: impl Into<Option<bool>>,
) -> &mut Self {
self.app.in_foreground = in_foreground.into();
self
}
/// Set the is_launching field of the App struct.
///
/// ```
/// use lemon_bugsnag_rs::error::payload::events::App;
///
/// let mut ab = App::builder();
///
/// // Give the is_launching a value.
/// ab.set_is_launching(false);
///
/// // Unset the is_launching.
/// ab.set_is_launching(None);
/// ```
pub fn set_is_launching(
&mut self,
is_launching: impl Into<Option<bool>>,
) -> &mut Self {
self.app.is_launching = is_launching.into();
self
}
/// Set the binary_arch field of the App struct.
///
/// ```
/// use lemon_bugsnag_rs::error::payload::events::App;
/// use lemon_bugsnag_rs::error::payload::events::enums::BinaryArch;
///
/// let mut ab = App::builder();
///
/// // Give the binary_arch a value.
/// ab.set_binary_arch(BinaryArch::Arm64);
///
/// // Unset the binary_arch.
/// ab.set_binary_arch(None);
/// ```
pub fn set_binary_arch(
&mut self,
binary_arch: impl Into<Option<BinaryArch>>,
) -> &mut Self {
self.app.binary_arch = binary_arch.into();
self
}
/// Set the running_on_rosetta field of the App struct.
///
/// ```
/// use lemon_bugsnag_rs::error::payload::events::App;
///
/// let mut ab = App::builder();
///
/// // Give the running_on_rosetta a value.
/// ab.set_running_on_rosetta(false);
///
/// // Unset the running_on_rosetta.
/// ab.set_running_on_rosetta(None);
/// ```
pub fn set_running_on_rosetta(
&mut self,
running_on_rosetta: impl Into<Option<bool>>,
) -> &mut Self {
self.app.running_on_rosetta = running_on_rosetta.into();
self
}
/// Generate an [App] struct using the options you set using the builder.
///
/// ```
/// use lemon_bugsnag_rs::error::payload::events::App;
/// use lemon_bugsnag_rs::error::payload::events::enums::BinaryArch;
///
/// let mut ab = App::builder();
///
/// ab.set_id("My doctest example app")
/// .set_version("1.0.0")
/// .set_binary_arch(BinaryArch::Amd64)
/// .set_in_foreground(true);
///
/// let app = ab.build();
/// ```
pub fn build(&self) -> App {
self.app.clone()
}
}
#[cfg(test)]
mod test {
#[cfg(feature = "optional-builders")]
#[test]
pub fn test_error_payload_events_app_builder() {
use crate::error::payload::events::enums::BinaryArch;
use crate::error::payload::events::App;
let test_app = App {
id: "1".to_string().into(),
version: "1.0".to_string().into(),
version_code: 1.into(),
bundle_version: "1.0".to_string().into(),
code_bundle_id: "20".to_string().into(),
build_uuid: "10".to_string().into(),
release_stage: "15".to_string().into(),
app_type: "rust".to_string().into(),
dsym_uuids: ["acx".into(), "poi".into()].to_vec().into(),
duration: 90000000.into(),
duration_in_foreground: 800000.into(),
in_foreground: true.into(),
is_launching: true.into(),
binary_arch: BinaryArch::Amd64.into(),
running_on_rosetta: false.into(),
};
let mut app_builder = App::builder();
let test_app_clone = test_app.clone();
let app = app_builder
.set_id(test_app_clone.id.as_deref())
.set_version(test_app_clone.version.as_deref())
.set_version_code(test_app_clone.version_code)
.set_bundle_version(test_app_clone.bundle_version.as_deref())
.set_code_bundle_id(test_app_clone.code_bundle_id.as_deref())
.set_build_uuid(test_app_clone.build_uuid.as_deref())
.set_release_stage(test_app_clone.release_stage.as_deref())
.set_app_type(test_app_clone.app_type.as_deref())
.set_dsym_uuids(test_app_clone.dsym_uuids)
.set_duration(test_app_clone.duration)
.set_duration_in_foreground(test_app_clone.duration_in_foreground)
.set_in_foreground(test_app_clone.in_foreground)
.set_is_launching(test_app_clone.is_launching)
.set_binary_arch(test_app_clone.binary_arch)
.set_running_on_rosetta(test_app_clone.running_on_rosetta)
.build();
assert_eq!(test_app, app);
}
}