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
#[cfg(doc)]
use crate::{Breadcrumb, Event, User};
use crate::{RToC, Value};
use std::collections::BTreeMap;
pub trait Object {
fn into_parts(self) -> (sys::Value, BTreeMap<String, Value>);
fn into_raw(self) -> sys::Value
where
Self: Sized,
{
let (raw, map) = self.into_parts();
for (key, value) in map {
let key = key.into_cstring();
match unsafe { sys::value_set_by_key(raw, key.as_ptr(), value.into_raw()) } {
0 => (),
_ => panic!("Sentry failed to allocate memory"),
}
}
raw
}
}
pub trait Map: Object {}
impl<K: Into<String>, V: Into<Value>> Map for Vec<(K, V)> {}
impl<K: Into<String>, V: Into<Value>> Object for Vec<(K, V)> {
fn into_parts(self) -> (sys::Value, BTreeMap<String, Value>) {
let map = self
.into_iter()
.map(|(k, v)| (k.into(), v.into()))
.collect();
(unsafe { sys::value_new_object() }, map)
}
}
impl<K: Into<String>, V: Into<Value>> Map for BTreeMap<K, V> {}
impl<K: Into<String>, V: Into<Value>> Object for BTreeMap<K, V> {
fn into_parts(self) -> (sys::Value, BTreeMap<String, Value>) {
let map = self
.into_iter()
.map(|(k, v)| (k.into(), v.into()))
.collect();
(unsafe { sys::value_new_object() }, map)
}
}