sentry_core/
breadcrumbs.rs

1use crate::protocol::Breadcrumb;
2/// A helper trait that converts self into an Iterator of Breadcrumbs.
3///
4/// This is used for the [`add_breadcrumb`] function.
5///
6/// [`add_breadcrumb`]: fn.add_breadcrumb.html
7pub trait IntoBreadcrumbs {
8    /// The iterator type for the breadcrumbs.
9    type Output: Iterator<Item = Breadcrumb>;
10
11    /// This converts the object into an optional breadcrumb.
12    fn into_breadcrumbs(self) -> Self::Output;
13}
14
15impl IntoBreadcrumbs for Breadcrumb {
16    type Output = std::iter::Once<Breadcrumb>;
17
18    fn into_breadcrumbs(self) -> Self::Output {
19        std::iter::once(self)
20    }
21}
22
23impl IntoBreadcrumbs for Vec<Breadcrumb> {
24    type Output = std::vec::IntoIter<Breadcrumb>;
25
26    fn into_breadcrumbs(self) -> Self::Output {
27        self.into_iter()
28    }
29}
30
31impl IntoBreadcrumbs for Option<Breadcrumb> {
32    type Output = std::option::IntoIter<Breadcrumb>;
33
34    fn into_breadcrumbs(self) -> Self::Output {
35        self.into_iter()
36    }
37}
38
39impl<F: FnOnce() -> I, I: IntoBreadcrumbs> IntoBreadcrumbs for F {
40    type Output = I::Output;
41
42    fn into_breadcrumbs(self) -> Self::Output {
43        self().into_breadcrumbs()
44    }
45}