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

Fix #174 #225

Merged
merged 2 commits into from
May 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/ser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl Serializer {

fn is_pretty(&self) -> bool {
match self.pretty {
Some((ref config, ref pretty)) => pretty.indent < config.depth_limit,
Some((ref config, ref pretty)) => pretty.indent <= config.depth_limit,
None => false,
}
}
Expand All @@ -244,7 +244,7 @@ impl Serializer {
fn start_indent(&mut self) {
if let Some((ref config, ref mut pretty)) = self.pretty {
pretty.indent += 1;
if pretty.indent < config.depth_limit {
if pretty.indent <= config.depth_limit {
let is_empty = self.is_empty.unwrap_or(false);

if !is_empty {
Expand All @@ -256,7 +256,7 @@ impl Serializer {

fn indent(&mut self) {
if let Some((ref config, ref pretty)) = self.pretty {
if pretty.indent < config.depth_limit {
if pretty.indent <= config.depth_limit {
self.output
.extend((0..pretty.indent).map(|_| config.indentor.as_str()));
}
Expand All @@ -265,7 +265,7 @@ impl Serializer {

fn end_indent(&mut self) {
if let Some((ref config, ref mut pretty)) = self.pretty {
if pretty.indent < config.depth_limit {
if pretty.indent <= config.depth_limit {
let is_empty = self.is_empty.unwrap_or(false);

if !is_empty {
Expand Down Expand Up @@ -567,7 +567,7 @@ impl<'a> ser::SerializeSeq for &'a mut Serializer {
self.output += ",";

if let Some((ref config, ref mut pretty)) = self.pretty {
if pretty.indent < config.depth_limit {
if pretty.indent <= config.depth_limit {
if config.enumerate_arrays {
assert!(config.new_line.contains('\n'));
let index = pretty.sequence_index.last_mut().unwrap();
Expand Down Expand Up @@ -611,7 +611,7 @@ impl<'a> ser::SerializeTuple for &'a mut Serializer {
self.output += ",";

if let Some((ref config, ref pretty)) = self.pretty {
if pretty.indent < config.depth_limit {
if pretty.indent <= config.depth_limit {
self.output += if self.separate_tuple_members() {
&config.new_line
} else {
Expand Down Expand Up @@ -697,7 +697,7 @@ impl<'a> ser::SerializeMap for &'a mut Serializer {
self.output += ",";

if let Some((ref config, ref pretty)) = self.pretty {
if pretty.indent < config.depth_limit {
if pretty.indent <= config.depth_limit {
self.output += &config.new_line;
}
}
Expand Down Expand Up @@ -734,7 +734,7 @@ impl<'a> ser::SerializeStruct for &'a mut Serializer {
self.output += ",";

if let Some((ref config, ref pretty)) = self.pretty {
if pretty.indent < config.depth_limit {
if pretty.indent <= config.depth_limit {
self.output += &config.new_line;
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/depth_limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fn depth_limit() {
};

let pretty = ron::ser::PrettyConfig::new()
.with_depth_limit(2)
.with_depth_limit(1)
.with_separate_tuple_members(true)
.with_enumerate_arrays(true)
.with_new_line("\n".to_string());
Expand Down