Skip to content

RUST-2019 Formatter for Bson ignores pretty printing {:#} #491

@mahmoud-moursy

Description

@mahmoud-moursy

Versions/Environment

  1. What version of Rust are you using?

rustc 1.82.0-nightly (506052d49 2024-08-16)

  1. What operating system are you using?

Linux

  1. What versions of the driver and its dependencies are you using? (Run
    cargo pkgid mongodb & cargo pkgid bson)
  • bson: registry+https://github.com/rust-lang/crates.io-index#[email protected]
  • mongodb: N/A
  1. What version of MongoDB are you using? (Check with the MongoDB shell using db.version())
    N/A
  2. What is your MongoDB topology (standalone, replica set, sharded cluster, serverless)?
    N/A

Describe the bug

A clear and concise description of what the bug is.

BE SPECIFIC:

  • What is the expected behavior and what is actually happening?
    Expected behaviour:

Bson formatting outputs the following:

{
  "key": "Hello world!"
}

What actually happens:

Bson formatting outputs the following:

{ "key": "Hello world!" }
  • Do you have any ideas on why this may be happening that could give us a
    clue in the right direction?

If you implemented Display manually, then you need to manually check if the user passed in pretty-printing
as a parameter and then change your formatting based on that.

You can check it using formatter.alternate() in your Display implementation.

  • Did this issue arise out of nowhere, or after an update (of the driver,
    server, and/or Rust)?
    The issue has likely existed for as long as the crate has.
  • Are there multiple ways of triggering this bug (perhaps more than one
    function produce a crash)?
    Nope. Only one, specifically. Formatting with {:#?} produces correctly-formatted output.
  • If you know how to reproduce this bug, please include a code snippet here:
let my_hashmap = HashMap::from([
  ("hello", "world!")
]);

let bson_document = bson::to_document(&my_hashmap);

// Incorrect formatting:
println!("{bson_document:#}");

// This, however, is correctly formatted:
println!("{bson_document:#?}");
// It is probably correctly formatted because the derive(Debug) implementation was used.

Thank you.

Metadata

Metadata

Assignees

Labels

tracked-in-jiraTicket filed in Mongo's Jira system

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions