Skip to content

Commit

Permalink
Access private NamedArgs APIs through __private module
Browse files Browse the repository at this point in the history
For consistency with other private APIs used by the binrw derives
that users should really not be using directly, do not export to
the root of the crate; instead, go through the `__private` module.
  • Loading branch information
csnover committed Jul 2, 2023
1 parent 7c52316 commit 8a49a5c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion binrw/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub use {
error::Error,
file_ptr::{FilePtr, FilePtr128, FilePtr16, FilePtr32, FilePtr64, FilePtr8},
helpers::{count, until, until_eof, until_exclusive},
named_args::*,
named_args::NamedArgs,
pos_value::PosValue,
strings::{NullString, NullWideString},
};
Expand Down
4 changes: 2 additions & 2 deletions binrw/src/named_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ macro_rules! args {
// since this helper is of PhantomData<T> -> T,
// and the compiler knows that the type Ret should be returned,
// it infers that args_ty should be of type PhantomData<Ret>.
$crate::passthrough_helper(args_ty)
$crate::__private::passthrough_helper(args_ty)
} else {
// we now pass the PhantomData<Ret> to a helper of PhantomData<T> -> T::Builder
// to obtain a builder for the type of the block.
let builder = $crate::builder_helper(args_ty);
let builder = $crate::__private::builder_helper(args_ty);

$(let builder = builder.$name($crate::args!(@ifn { $($value)? } $name));)*

Expand Down
4 changes: 4 additions & 0 deletions binrw/src/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ use crate::{
};
use alloc::{boxed::Box, string::String};

pub use crate::named_args::{
builder_helper, passthrough_helper, Needed, Optional, Satisfied, SatisfiedOrOptional,
};

// This is some nonsense to improve the diagnostic output for types that require
// arguments so that the emitted output is clearer about this fact. Because this
// is implemented for any `Default`, and used as the constraint for shorthand
Expand Down
8 changes: 4 additions & 4 deletions binrw_derive/src/named_args/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use quote::{quote, ToTokens};
use syn::{GenericArgument, GenericParam, Ident, Type, Visibility};

ident_str! {
SATISFIED_OR_OPTIONAL = from_crate!(SatisfiedOrOptional);
SATISFIED = from_crate!(Satisfied);
NEEDED = from_crate!(Needed);
OPTIONAL = from_crate!(Optional);
SATISFIED_OR_OPTIONAL = from_crate!(__private::SatisfiedOrOptional);
SATISFIED = from_crate!(__private::Satisfied);
NEEDED = from_crate!(__private::Needed);
OPTIONAL = from_crate!(__private::Optional);
NAMED_ARGS = from_crate!(NamedArgs);
}

Expand Down

0 comments on commit 8a49a5c

Please sign in to comment.