@@ -70,6 +70,15 @@ impl From<anyhow::Result<()>> for ProfileResult {
70
70
}
71
71
}
72
72
73
+ impl From < ProfileResult > for Result < ( ) , Error > {
74
+ fn from ( result : ProfileResult ) -> Self {
75
+ match result {
76
+ ProfileResult :: Ok ( _) => Ok ( ( ) ) ,
77
+ ProfileResult :: Err ( err) => Err ( err) ,
78
+ }
79
+ }
80
+ }
81
+
73
82
/// Returned by [ddog_prof_Profile_new].
74
83
#[ allow( dead_code) ]
75
84
#[ repr( C ) ]
@@ -79,6 +88,15 @@ pub enum ProfileNewResult {
79
88
Err ( Error ) ,
80
89
}
81
90
91
+ impl From < ProfileNewResult > for Result < Profile , Error > {
92
+ fn from ( value : ProfileNewResult ) -> Self {
93
+ match value {
94
+ ProfileNewResult :: Ok ( v) => Ok ( v) ,
95
+ ProfileNewResult :: Err ( e) => Err ( e) ,
96
+ }
97
+ }
98
+ }
99
+
82
100
#[ allow( dead_code) ]
83
101
#[ repr( C ) ]
84
102
pub enum SerializeResult {
@@ -390,7 +408,7 @@ impl<'a> From<Sample<'a>> for api::StringIdSample<'a> {
390
408
/// time.
391
409
///
392
410
/// # Safety
393
- /// All slices must be have pointers that are suitably aligned for their type
411
+ /// All slices must have pointers that are suitably aligned for their type
394
412
/// and must have the correct number of elements for the slice.
395
413
#[ no_mangle]
396
414
#[ must_use]
@@ -447,26 +465,6 @@ pub unsafe extern "C" fn ddog_prof_Profile_drop(profile: *mut Profile) {
447
465
}
448
466
}
449
467
450
- #[ cfg( test) ]
451
- impl From < ProfileResult > for Result < ( ) , Error > {
452
- fn from ( result : ProfileResult ) -> Self {
453
- match result {
454
- ProfileResult :: Ok ( _) => Ok ( ( ) ) ,
455
- ProfileResult :: Err ( err) => Err ( err) ,
456
- }
457
- }
458
- }
459
-
460
- #[ cfg( test) ]
461
- impl From < ProfileNewResult > for Result < Profile , Error > {
462
- fn from ( result : ProfileNewResult ) -> Self {
463
- match result {
464
- ProfileNewResult :: Ok ( p) => Ok ( p) ,
465
- ProfileNewResult :: Err ( err) => Err ( err) ,
466
- }
467
- }
468
- }
469
-
470
468
/// # Safety
471
469
/// The `profile` ptr must point to a valid Profile object created by this
472
470
/// module. All pointers inside the `sample` need to be valid for the duration
@@ -547,6 +545,50 @@ pub unsafe extern "C" fn ddog_prof_Profile_set_endpoint(
547
545
. into ( )
548
546
}
549
547
548
+ /// Sets the profile's upload compression algorithm. Useful only for testing.
549
+ ///
550
+ /// # Examples
551
+ ///
552
+ /// ```
553
+ /// # use datadog_profiling_ffi::{Error, ddog_prof_Profile_set_upload_compression, ddog_prof_Profile_new, ValueType, Slice, CharSlice};
554
+ /// # use std::ptr::addr_of_mut;
555
+ /// # fn main() -> Result<(), Error> { unsafe {
556
+ /// use datadog_profiling::UploadCompression;
557
+ ///
558
+ /// let mut profile = Result::from(ddog_prof_Profile_new(
559
+ /// Slice::from([ValueType {
560
+ /// type_: CharSlice::from("sample"),
561
+ /// unit: CharSlice::from("count"),
562
+ /// }].as_slice()),
563
+ /// None,
564
+ /// ))?;
565
+ ///
566
+ /// // Set compression off (only for testing).
567
+ /// Result::from(ddog_prof_Profile_set_upload_compression(
568
+ /// addr_of_mut!(profile),
569
+ /// UploadCompression::Off
570
+ /// ))?;
571
+ /// # } Ok(()) }
572
+ /// ```
573
+ #[ no_mangle]
574
+ #[ must_use]
575
+ #[ named]
576
+ pub unsafe extern "C" fn ddog_prof_Profile_set_upload_compression (
577
+ profile : * mut Profile ,
578
+ upload_compression : datadog_profiling:: UploadCompression ,
579
+ ) -> ProfileResult {
580
+ match profile_ptr_to_inner ( profile) {
581
+ Ok ( profile) => {
582
+ profile. set_upload_compression ( upload_compression) ;
583
+ ProfileResult :: Ok ( true )
584
+ }
585
+ Err ( err) => {
586
+ let e = err. context ( concat ! ( function_name!( ) , " failed" ) ) ;
587
+ ProfileResult :: Err ( e. into ( ) )
588
+ }
589
+ }
590
+ }
591
+
550
592
/// Count the number of times an endpoint has been seen.
551
593
///
552
594
/// # Arguments
0 commit comments