Skip to content

Commit 9da736d

Browse files
committed
RUST-765 Ensure public structs are future proof (C-STRUCT-PRIVATE)
1 parent 8a92a56 commit 9da736d

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

src/de/error.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub enum Error {
1717

1818
/// While decoding a `Document` from bytes, an unexpected or unsupported element type was
1919
/// encountered.
20+
#[non_exhaustive]
2021
UnrecognizedDocumentElementType {
2122
/// The key at which an unexpected/unsupported element type was encountered.
2223
key: String,
@@ -26,12 +27,14 @@ pub enum Error {
2627
},
2728

2829
/// There was an error with the syntactical structure of the BSON.
30+
#[non_exhaustive]
2931
SyntaxError { message: String },
3032

3133
/// The end of the BSON input was reached too soon.
3234
EndOfStream,
3335

3436
/// An invalid datetime was encountered while decoding.
37+
#[non_exhaustive]
3538
InvalidDateTime {
3639
/// The key at which an unexpected/unsupported datetime was encountered.
3740
key: String,
@@ -42,6 +45,7 @@ pub enum Error {
4245

4346
/// A general error encountered during deserialization.
4447
/// See: https://docs.serde.rs/serde/de/trait.Error.html
48+
#[non_exhaustive]
4549
DeserializationError {
4650
/// A message describing the error.
4751
message: String,

src/de/serde.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::{
2323
spec::BinarySubtype,
2424
};
2525

26-
pub struct BsonVisitor;
26+
pub(crate) struct BsonVisitor;
2727

2828
impl<'de> Deserialize<'de> for ObjectId {
2929
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>

src/ser/error.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@ pub enum Error {
1212
IoError(Arc<io::Error>),
1313

1414
/// A key could not be serialized to a BSON string.
15-
InvalidMapKeyType {
16-
/// The value that could not be used as a key.
17-
key: Bson,
18-
},
15+
InvalidDocumentKey(Bson),
1916

2017
/// Attempted to serialize a sub-millisecond precision datetime, which BSON does not support.
2118
SubMillisecondPrecisionDateTime(crate::DateTime),
2219

2320
/// A general error that ocurred during serialization.
2421
/// See: https://docs.rs/serde/1.0.110/serde/ser/trait.Error.html#tymethod.custom
22+
#[non_exhaustive]
2523
SerializationError {
2624
/// A message describing the error.
2725
message: String,
@@ -50,7 +48,7 @@ impl fmt::Display for Error {
5048
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
5149
match *self {
5250
Error::IoError(ref inner) => inner.fmt(fmt),
53-
Error::InvalidMapKeyType { ref key } => write!(fmt, "Invalid map key type: {}", key),
51+
Error::InvalidDocumentKey(ref key) => write!(fmt, "Invalid map key type: {}", key),
5452
Error::SerializationError { ref message } => message.fmt(fmt),
5553
#[cfg(not(feature = "u2i"))]
5654
Error::UnsupportedUnsignedInteger(value) => write!(

src/ser/serde.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ impl Serialize for Bson {
8484
}
8585

8686
/// Serde Serializer
87+
#[non_exhaustive]
8788
pub struct Serializer;
8889

8990
impl Serializer {
@@ -440,7 +441,7 @@ impl SerializeMap for MapSerializer {
440441
fn serialize_key<T: ?Sized + Serialize>(&mut self, key: &T) -> crate::ser::Result<()> {
441442
self.next_key = match to_bson(&key)? {
442443
Bson::String(s) => Some(s),
443-
other => return Err(Error::InvalidMapKeyType { key: other }),
444+
other => return Err(Error::InvalidDocumentKey(other)),
444445
};
445446
Ok(())
446447
}

0 commit comments

Comments
 (0)