I'm building a crate for reading and writing a file format. Reading is accomplished via nom parser-combinators. As a result I have lots of small parser methods like:
named!(read_prop_fs<&[u8], PropChunk>, do_parse!(
tag!("FS ") >>
size: be_u64 >>
fs: be_u32 >>
(PropChunk { id: PropId::FS(fs), size: size })
));
The parser functions are in io::input::internal and are all private. Most of the data types they use are also private to that module.
The file writer code I would like to test is in io::output::internal. Ideally, I would like to use the parser functions in unit tests for the writer.
Making all these methods and types pub or even crate seems very ugly. It seems equally strange to invert the modules, having the equivalent of io::internal::{input, output} where input and output are ultimately pub and represent the crate API.
Is there a way to do something like this?
When
#[cfg(test)]is true the default visibility in the current module should becrate, otherwise the default should be private.
If not, is there a typical, ergonomic workaround?