Skip to content

Commit

Permalink
lib: remove pub export of macros
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cpu committed Oct 13, 2023
1 parent 318c54b commit b13c99d
Showing 1 changed file with 12 additions and 23 deletions.
35 changes: 12 additions & 23 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,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) {
Expand All @@ -530,6 +528,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.
///
Expand All @@ -554,8 +554,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) {
Expand All @@ -565,6 +563,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.
///
Expand All @@ -581,8 +581,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) {
Expand All @@ -592,6 +590,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`].
///
Expand All @@ -608,8 +608,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) {
Expand All @@ -619,8 +617,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() {
Expand All @@ -631,20 +629,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 {
Expand All @@ -653,6 +639,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.
Expand Down

0 comments on commit b13c99d

Please sign in to comment.