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
pub use relay_base_schema::data_category::DataCategory;
pub use relay_base_schema::events::EventType;
pub use relay_base_schema::spans::SpanStatus;

use crate::core::RelayStr;

/// Returns the API name of the given `DataCategory`.
#[no_mangle]
#[relay_ffi::catch_unwind]
pub unsafe extern "C" fn relay_data_category_name(category: DataCategory) -> RelayStr {
    RelayStr::new(category.name())
}

/// Parses a `DataCategory` from its API name.
#[no_mangle]
#[relay_ffi::catch_unwind]
pub unsafe extern "C" fn relay_data_category_parse(name: *const RelayStr) -> DataCategory {
    (*name).as_str().parse().unwrap_or(DataCategory::Unknown)
}

/// Parses a `DataCategory` from an event type.
#[no_mangle]
#[relay_ffi::catch_unwind]
pub unsafe extern "C" fn relay_data_category_from_event_type(
    event_type: *const RelayStr,
) -> DataCategory {
    (*event_type)
        .as_str()
        .parse::<EventType>()
        .unwrap_or_default()
        .into()
}