Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistify custom formatting with custom parsing and expose in the public API #54

Merged
merged 12 commits into from
Aug 8, 2024

Conversation

jsdw
Copy link
Collaborator

@jsdw jsdw commented Jul 29, 2024

This PR exposes two new functions for formatting values, crate::stringify::to_writer and crate::stringify::to_writer_custom (to align with the already present crate::stringify::from_str_custom), and also exposes a new crate::stringiy::custom_formatters containing a formatter for displaying things as hex.

to_writer_custom exposes a ToWriterBuilder. This provides options for customising the output of a value, such as a compact mode or a spaced mode for pretty printing values, and options to configure the indentation of spaced values. A way to print the value context information is also exposed.

Some of this logic was already added in #52, but now it is being extended and exposed for general usage.

/// bar: true
/// }"#);
/// ```
pub fn spaced(mut self) -> Self {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: indented

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmm spaced isn't the best word for this is it! I was also thinking pretty to align with eg serde_json's use of the word!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that would also be a good name

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to pretty; thanks for pointing this out!

src/string_impls/to_string.rs Show resolved Hide resolved
src/string_impls/to_string.rs Show resolved Hide resolved
@jsdw jsdw merged commit a3c27a3 into main Aug 8, 2024
8 checks passed
@jsdw jsdw deleted the jsdw-to-writer branch August 8, 2024 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants