@@ -70,6 +70,15 @@ impl From<anyhow::Result<()>> for ProfileResult {
7070 }
7171}
7272
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+
7382/// Returned by [ddog_prof_Profile_new].
7483#[ allow( dead_code) ]
7584#[ repr( C ) ]
@@ -79,6 +88,15 @@ pub enum ProfileNewResult {
7988 Err ( Error ) ,
8089}
8190
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+
82100#[ allow( dead_code) ]
83101#[ repr( C ) ]
84102pub enum SerializeResult {
@@ -390,7 +408,7 @@ impl<'a> From<Sample<'a>> for api::StringIdSample<'a> {
390408/// time.
391409///
392410/// # 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
394412/// and must have the correct number of elements for the slice.
395413#[ no_mangle]
396414#[ must_use]
@@ -401,7 +419,11 @@ pub unsafe extern "C" fn ddog_prof_Profile_new(
401419 profile_new ( sample_types, period, None )
402420}
403421
404- /// Same as `ddog_profile_new` but also configures a `string_storage` for the profile.
422+ /// Same as [ddog_prof_Profile_new] but also configures a `string_storage` for
423+ /// the profile.
424+ ///
425+ /// # Safety
426+ /// Has all same safety conditions as [ddog_prof_Profile_new].
405427#[ no_mangle]
406428#[ must_use]
407429/// TODO: @ivoanjo Should this take a `*mut ManagedStringStorage` like Profile APIs do?
@@ -447,26 +469,6 @@ pub unsafe extern "C" fn ddog_prof_Profile_drop(profile: *mut Profile) {
447469 }
448470}
449471
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-
470472/// # Safety
471473/// The `profile` ptr must point to a valid Profile object created by this
472474/// module. All pointers inside the `sample` need to be valid for the duration
@@ -547,6 +549,58 @@ pub unsafe extern "C" fn ddog_prof_Profile_set_endpoint(
547549 . into ( )
548550}
549551
552+ /// Sets the profile's upload compression algorithm. Useful only for testing.
553+ ///
554+ /// # Errors
555+ ///
556+ /// Returns an error if either the pointer or the inner profiler ptr is null.
557+ ///
558+ /// # Safety
559+ ///
560+ /// The `profile` ptr must point to a valid Profile object.
561+ ///
562+ /// # Examples
563+ ///
564+ /// ```
565+ /// # use datadog_profiling_ffi::{Error, ddog_prof_Profile_set_upload_compression, ddog_prof_Profile_new, ValueType, Slice, CharSlice};
566+ /// # use std::ptr::addr_of_mut;
567+ /// # fn main() -> Result<(), Error> { unsafe {
568+ /// use datadog_profiling::UploadCompression;
569+ ///
570+ /// let mut profile = Result::from(ddog_prof_Profile_new(
571+ /// Slice::from([ValueType {
572+ /// type_: CharSlice::from("sample"),
573+ /// unit: CharSlice::from("count"),
574+ /// }].as_slice()),
575+ /// None,
576+ /// ))?;
577+ ///
578+ /// // Set compression off (only for testing).
579+ /// Result::from(ddog_prof_Profile_set_upload_compression(
580+ /// addr_of_mut!(profile),
581+ /// UploadCompression::Off
582+ /// ))?;
583+ /// # } Ok(()) }
584+ /// ```
585+ #[ no_mangle]
586+ #[ must_use]
587+ #[ named]
588+ pub unsafe extern "C" fn ddog_prof_Profile_set_upload_compression (
589+ profile : * mut Profile ,
590+ upload_compression : datadog_profiling:: UploadCompression ,
591+ ) -> ProfileResult {
592+ match profile_ptr_to_inner ( profile) {
593+ Ok ( profile) => {
594+ profile. set_upload_compression ( upload_compression) ;
595+ ProfileResult :: Ok ( true )
596+ }
597+ Err ( err) => {
598+ let e = err. context ( concat ! ( function_name!( ) , " failed" ) ) ;
599+ ProfileResult :: Err ( e. into ( ) )
600+ }
601+ }
602+ }
603+
550604/// Count the number of times an endpoint has been seen.
551605///
552606/// # Arguments
@@ -759,6 +813,14 @@ pub unsafe extern "C" fn ddog_prof_Profile_serialize(
759813 . into ( )
760814}
761815
816+ /// Borrows FFI Vec as an FFI Slice.
817+ ///
818+ /// # Safety
819+ /// The input needs to be a valid reference to an FFI Vec, and the slice needs
820+ /// to be used in a way consistent with the lifetime and safety rules. Some
821+ /// things to avoid:
822+ /// - Do not modify the Vec at all while the Slice is alive.
823+ /// - Do not drop the Vec while the Slice is alive.
762824#[ must_use]
763825#[ no_mangle]
764826pub unsafe extern "C" fn ddog_Vec_U8_as_slice ( vec : & ddcommon_ffi:: Vec < u8 > ) -> Slice < u8 > {
0 commit comments