@@ -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,58 @@ 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
+ /// # Errors
551
+ ///
552
+ /// Returns an error if either the pointer or the inner profiler ptr is null.
553
+ ///
554
+ /// # Safety
555
+ ///
556
+ /// The `profile` ptr must point to a valid Profile object.
557
+ ///
558
+ /// # Examples
559
+ ///
560
+ /// ```
561
+ /// # use datadog_profiling_ffi::{Error, ddog_prof_Profile_set_upload_compression, ddog_prof_Profile_new, ValueType, Slice, CharSlice};
562
+ /// # use std::ptr::addr_of_mut;
563
+ /// # fn main() -> Result<(), Error> { unsafe {
564
+ /// use datadog_profiling::UploadCompression;
565
+ ///
566
+ /// let mut profile = Result::from(ddog_prof_Profile_new(
567
+ /// Slice::from([ValueType {
568
+ /// type_: CharSlice::from("sample"),
569
+ /// unit: CharSlice::from("count"),
570
+ /// }].as_slice()),
571
+ /// None,
572
+ /// ))?;
573
+ ///
574
+ /// // Set compression off (only for testing).
575
+ /// Result::from(ddog_prof_Profile_set_upload_compression(
576
+ /// addr_of_mut!(profile),
577
+ /// UploadCompression::Off
578
+ /// ))?;
579
+ /// # } Ok(()) }
580
+ /// ```
581
+ #[ no_mangle]
582
+ #[ must_use]
583
+ #[ named]
584
+ pub unsafe extern "C" fn ddog_prof_Profile_set_upload_compression (
585
+ profile : * mut Profile ,
586
+ upload_compression : datadog_profiling:: UploadCompression ,
587
+ ) -> ProfileResult {
588
+ match profile_ptr_to_inner ( profile) {
589
+ Ok ( profile) => {
590
+ profile. set_upload_compression ( upload_compression) ;
591
+ ProfileResult :: Ok ( true )
592
+ }
593
+ Err ( err) => {
594
+ let e = err. context ( concat ! ( function_name!( ) , " failed" ) ) ;
595
+ ProfileResult :: Err ( e. into ( ) )
596
+ }
597
+ }
598
+ }
599
+
550
600
/// Count the number of times an endpoint has been seen.
551
601
///
552
602
/// # Arguments
0 commit comments