Currently generally emitting diagnostics is based on the internal GeneralWrite. This is core::fmt::Write when the std feature is missing and std::io::Write when feature std is enabled.
They have some similarities such as write_str and being passed to the first argument of writeln!. They have several differences: what types implement each trait, std::io::Write has a flush method and they have different error types in the write_str Result.
Before 0.13.0 this reuse of writeln! and the swapping of traits caused issues. For example String could be written to with --no-default-features but broke when a feature was added (#389). Since #400 this has been better handled through the addition of different functions for different writers. For example the emit_to_string function.
However, just there are still issues if the user does not pick a designated function.
A implementer of WriteStyle that wants to be usable with and without the std feature has to be aware of the differences. While possible (see example), it is not great.
I have considered a unified SuperWrite trait but have not been able to figure anything that works well with write! macros etc.
Another possible solution to remove this GeneralWrite tricks is
- Add a feature like
fmt-write
- Contain all code in
mod renderer_io
- Create a macro that
#[cfg(feature = "fmt-write")] include_mod_rewrite_io_to_fmt(mod renderer_io)...
Currently generally emitting diagnostics is based on the internal
GeneralWrite. This iscore::fmt::Writewhen thestdfeature is missing andstd::io::Writewhen featurestdis enabled.They have some similarities such as
write_strand being passed to the first argument ofwriteln!. They have several differences: what types implement each trait,std::io::Writehas aflushmethod and they have different error types in thewrite_strResult.Before 0.13.0 this reuse of
writeln!and the swapping of traits caused issues. For exampleStringcould be written to with--no-default-featuresbut broke when a feature was added (#389). Since #400 this has been better handled through the addition of different functions for different writers. For example theemit_to_stringfunction.However, just there are still issues if the user does not pick a designated function.
A implementer of
WriteStylethat wants to be usable with and without thestdfeature has to be aware of the differences. While possible (see example), it is not great.I have considered a unified
SuperWritetrait but have not been able to figure anything that works well withwrite!macros etc.Another possible solution to remove this
GeneralWritetricks isfmt-writemod renderer_io#[cfg(feature = "fmt-write")] include_mod_rewrite_io_to_fmt(mod renderer_io)...