Skip to content

Commit 3cc6dd3

Browse files
authored
RUST-1617 Update Decimal128 documentation with examples of string roundtrips. (#409)
1 parent 7c46ba9 commit 3cc6dd3

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/decimal128.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,21 @@ use bitvec::prelude::*;
66

77
/// Struct representing a BSON Decimal128 type.
88
///
9-
/// Currently, this type can only be used to round-trip through BSON. See
10-
/// [RUST-36](https://jira.mongodb.org/browse/RUST-36) to track the progress towards a complete implementation.
9+
/// This type supports conversion to and from human-readable strings via the [std::fmt::Display] and
10+
/// [std::str::FromStr] traits:
11+
///
12+
/// ```rust
13+
/// # use std::str::FromStr;
14+
/// # use bson::Decimal128;
15+
/// # fn example() -> std::result::Result<(), Box<dyn std::error::Error>> {
16+
/// let value: Decimal128 = "3.14159".parse()?;
17+
/// assert_eq!("3.14159", format!("{}", value));
18+
/// let scientific = Decimal128::from_str("1.05E+3")?;
19+
/// assert_eq!("1.05E+3", scientific.to_string());
20+
/// # Ok(())
21+
/// # }
22+
/// # example().unwrap()
23+
/// ```
1124
#[derive(Copy, Clone, PartialEq)]
1225
pub struct Decimal128 {
1326
/// BSON bytes containing the decimal128. Stored for round tripping.

0 commit comments

Comments
 (0)