-
Notifications
You must be signed in to change notification settings - Fork 123
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
Pretty configuration options #61
Conversation
Non-separated tuple members: (
float: (2.180000066757202, -1.1),
tuple: ((), false),
map: {
0: '1',
3: '5',
8: '1',
1: '2',
},
nested: (
a: "Hello from \"RON\"",
b: 'b',
),
var: A(255, ""),
) Separated tuple members: (
float: (
2.180000066757202,
-1.1,
),
tuple: (
(),
false,
),
map: {
8: '1',
0: '1',
3: '5',
1: '2',
},
nested: (
a: "Hello from \"RON\"",
b: 'b',
),
var: A(
255,
"",
),
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I love these options. Also solves the question about which line endings to use. Found a few nits, see below.
fn default() -> Self { | ||
PrettyConfig { | ||
#[cfg(not(target_os = "windows"))] | ||
new_line: "\n".to_string(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea!
src/ser/mod.rs
Outdated
struct_names: bool, | ||
} | ||
|
||
impl Serializer { | ||
fn separate_tuple_members(&self) -> bool { | ||
match self.pretty { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: could use map
and unwrap_or
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it would look much better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just the style that seems to be preferred. You can also leave it as is if you prefer this style.
src/ser/pretty.rs
Outdated
use serde::ser::Serialize; | ||
|
||
/// Serializes `value` in the recommended RON layout. | ||
pub fn to_string<T>(value: &T) -> Result<String> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see why we have to make this a breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we just add a second variant and leave this function, using PrettyConfig::default
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if it's worth it? All it takes from the user is to pass in default()
as a parameter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
although, you are right, by keeping the old function we can make it a non-breaking change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I just don't see why we should bump the version.
/// New line string | ||
pub new_line: String, | ||
/// Indentation string | ||
pub indentor: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could theoretically use &str
or &[u8]
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried, facing the lifetime hell since the &'a
(assuming we don't want &'static
) starts polluting Serializer
struct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, let's leave it like that then. Pretty serialization isn't something that suffers from two string allocations I guess.
src/ser/mod.rs
Outdated
struct Pretty { | ||
indent: usize, | ||
} | ||
|
||
/// Pretty serializer configuration | ||
pub struct PrettyConfig { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's derive Copy
, Clone
, Debug
and serde traits for this struct.
Thanks for the review, please take another look! |
src/ser/mod.rs
Outdated
use std::fmt::{Display, Formatter, Result as FmtResult}; | ||
|
||
use serde::ser::{self, Serialize}; | ||
|
||
#[deprecated] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't deprecate it. Better just move the new function to that module. If you really want to, we should give an explanation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see why we need pretty
module, it's empty and serves no solid purpose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And what deprecated
tells you is basically that it's going to be cut off in the next breaking release, which is what I wanted to do in the first place :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but let's add an explanation that one should simply use to_string_pretty
with a default config instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So #[deprecated(since="0.1.4", note="please use to_string_pretty
with PrettyConfig::default()
instead")]
@torkleyy agreed. How about now? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! After you've addressed that last thing, feel free to merge.
src/ser/mod.rs
Outdated
struct Pretty { | ||
indent: usize, | ||
} | ||
|
||
/// Pretty serializer configuration | ||
#[derive(Clone, Debug)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need Deserialize
and Serialize
, too.
Unfortunately, that would require serde_derive dependency in non-test configuration
… On Oct 11, 2017, at 16:20, Thomas Schaller ***@***.***> wrote:
@torkleyy approved this pull request.
Thanks! After you've addressed that last thing, feel free to merge.
In src/ser/mod.rs:
> struct Pretty {
indent: usize,
}
+/// Pretty serializer configuration
+#[derive(Clone, Debug)]
We need Deserialize and Serialize, too.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
So what's the problem? |
@torkleyy well, one more dependency imposed for all the users. Not sure if it's worth it, considering how marginal the need to serialize the config is. |
@kvark serde re-exports serde_derive if you use the "derive" feature flag I believe. |
This can be done later at any point, if anyone requests the feature.
… On Oct 11, 2017, at 17:52, Aceeri ***@***.***> wrote:
@kvark serde re-exports serde_derive if you use the "derive" feature flag I believe.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
@torkleyy added serde_derive unconditionally now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for addressing all my concerns!
Let's, finally, merge this :) bors r+ |
Build succeeded |
Fixes #58
BREAKING CHANGE