Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Add a to_string_pretty method #226

Closed
MarcoIeni opened this issue Nov 30, 2021 · 1 comment
Closed

Add a to_string_pretty method #226

MarcoIeni opened this issue Nov 30, 2021 · 1 comment

Comments

@MarcoIeni
Copy link

MarcoIeni commented Nov 30, 2021

I would like to be able to print in a different way \n inside strings.
Example:

use serde::Serialize;

#[derive(Serialize, Debug)]
struct A {
    b: String,
    c: String,
}

fn main() {
    let a = A {
        b: "aaa\nbbb\n".to_string(),
        c: "ccc".to_string(),
    };
    let yaml = serde_yaml::to_string(&a).unwrap();
    println!("{}", yaml);
}

prints:

---
b: "aaa\nbbb\n"
c: ccc

Instead I would like to have:

---
b: |
  aaa
  bbb
c: cccc

Maybe this could be a good fit for a function similar to serde_json::to_string_pretty

@dtolnay
Copy link
Owner

dtolnay commented Jul 28, 2022

As of 0.9 the formatting is prettier by default so a separate method shouldn't be needed.

@dtolnay dtolnay closed this as completed Jul 28, 2022
Repository owner locked and limited conversation to collaborators Feb 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants