From fbeec7fdaac8a217c8f08d310e0fdfea13c7df60 Mon Sep 17 00:00:00 2001 From: Daniel McCarney Date: Fri, 13 Oct 2023 15:11:47 -0400 Subject: [PATCH] lib: remove pub export of macros Previously the helper macros in `src/lib.rs` were marked `macro_export`, making them part of the public API. Since these were meant to be crate internal, we also annotated the macros as `doc(hidden)` to avoid them appearing in the API docs. I suspect this was done before `pub(crate)` visibility was an option. This commit removes the `macro_export` and `doc(hidden)` attributes and uses a `pub(crate)` re-export to make the macros available to crate-internal users without making them part of the public API. Along the way this uncovered that the `try_mut_slice!` macro wasn't being used anywhere and so it is removed outright. --- src/lib.rs | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 6092f628..c66d0954 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -510,8 +510,6 @@ where /// ```rust,ignore /// let config: &mut ClientConfig = try_mut_from_ptr!(builder); /// ``` -#[doc(hidden)] -#[macro_export] macro_rules! try_mut_from_ptr { ( $var:ident ) => { match $crate::try_from_mut($var) { @@ -521,6 +519,8 @@ macro_rules! try_mut_from_ptr { }; } +pub(crate) use try_mut_from_ptr; + /// Converts a const pointer to a [`Castable`] to an optional ref to the underlying /// [`Castable::RustType`]. See [`cast_const_ptr`] for more information. /// @@ -545,8 +545,6 @@ where /// ```rust, ignore /// let config: &ClientConfig = try_ref_from_ptr!(builder); /// ``` -#[doc(hidden)] -#[macro_export] macro_rules! try_ref_from_ptr { ( $var:ident ) => { match $crate::try_from($var) { @@ -556,6 +554,8 @@ macro_rules! try_ref_from_ptr { }; } +pub(crate) use try_ref_from_ptr; + /// Convert a const pointer to a [`Castable`] to an optional `Arc` over the underlying /// [`Castable::RustType`]. See [`to_arc`] for more information. /// @@ -572,8 +572,6 @@ where /// the underlying rust type using [`try_arc_from`]. Otherwise, return /// [`rustls_result::NullParameter`], or an appropriate default (`false`, `0`, `NULL`) based on the /// context. See [`try_arc_from`] for more information. -#[doc(hidden)] -#[macro_export] macro_rules! try_arc_from_ptr { ( $var:ident ) => { match $crate::try_arc_from($var) { @@ -583,6 +581,8 @@ macro_rules! try_arc_from_ptr { }; } +pub(crate) use try_arc_from_ptr; + /// Convert a mutable pointer to a [`Castable`] to an optional `Box` over the underlying /// [`Castable::RustType`]. /// @@ -599,8 +599,6 @@ where /// over the underlying rust type using [`try_box_from`]. Otherwise, return [`rustls_result::NullParameter`], /// or an appropriate default (`false`, `0`, `NULL`) based on the context. See [`try_box_from`] for /// more information. -#[doc(hidden)] -#[macro_export] macro_rules! try_box_from_ptr { ( $var:ident ) => { match $crate::try_box_from($var) { @@ -610,8 +608,8 @@ macro_rules! try_box_from_ptr { }; } -#[doc(hidden)] -#[macro_export] +pub(crate) use try_box_from_ptr; + macro_rules! try_slice { ( $ptr:expr, $count:expr ) => { if $ptr.is_null() { @@ -622,20 +620,8 @@ macro_rules! try_slice { }; } -#[doc(hidden)] -#[macro_export] -macro_rules! try_mut_slice { - ( $ptr:expr, $count:expr ) => { - if $ptr.is_null() { - return $crate::panic::NullParameterOrDefault::value(); - } else { - unsafe { slice::from_raw_parts_mut($ptr, $count as usize) } - } - }; -} +pub(crate) use try_slice; -#[doc(hidden)] -#[macro_export] macro_rules! try_callback { ( $var:ident ) => { match $var { @@ -644,6 +630,9 @@ macro_rules! try_callback { } }; } + +pub(crate) use try_callback; + /// Returns a static string containing the rustls-ffi version as well as the /// rustls version. The string is alive for the lifetime of the program and does /// not need to be freed.