diff --git a/src/binary.rs b/src/binary.rs index e7a8e789..2a6d0fa3 100644 --- a/src/binary.rs +++ b/src/binary.rs @@ -28,7 +28,7 @@ impl Display for Binary { impl Binary { /// Creates a [`Binary`] from a base64 string and optional [`BinarySubtype`]. If the - /// `subtype` argument is `None`, the [`Binary`] constructed will default to + /// `subtype` argument is [`None`], the [`Binary`] constructed will default to /// [`BinarySubtype::Generic`]. /// /// ```rust @@ -83,7 +83,7 @@ impl Binary { } } - /// Borrow the contents as a `RawBinaryRef`. + /// Borrow the contents as a [`RawBinaryRef`]. pub fn as_raw_binary(&self) -> RawBinaryRef<'_> { RawBinaryRef { bytes: self.bytes.as_slice(), diff --git a/src/bson.rs b/src/bson.rs index bb8af34f..3780b12e 100644 --- a/src/bson.rs +++ b/src/bson.rs @@ -514,7 +514,7 @@ impl Bson { } } - /// Get the `ElementType` of this value. + /// Get the [`ElementType`] of this value. pub fn element_type(&self) -> ElementType { match *self { Bson::Double(..) => ElementType::Double, @@ -841,7 +841,8 @@ impl Bson { /// Value helpers impl Bson { - /// If `Bson` is `Double`, return its value as an `f64`. Returns `None` otherwise + /// If `self` is [`Double`](Bson::Double), return its value as an `f64`. Returns [`None`] + /// otherwise. pub fn as_f64(&self) -> Option { match *self { Bson::Double(v) => Some(v), @@ -849,7 +850,8 @@ impl Bson { } } - /// If `Bson` is `String`, return its value as a `&str`. Returns `None` otherwise + /// If `self` is [`String`](Bson::String), return its value as a `&str`. Returns [`None`] + /// otherwise. pub fn as_str(&self) -> Option<&str> { match *self { Bson::String(ref s) => Some(s), @@ -857,8 +859,8 @@ impl Bson { } } - /// If `Bson` is `String`, return a mutable reference to its value as a `str`. Returns `None` - /// otherwise + /// If `self` is [`String`](Bson::String), return a mutable reference to its value as a [`str`]. + /// Returns [`None`] otherwise. pub fn as_str_mut(&mut self) -> Option<&mut str> { match *self { Bson::String(ref mut s) => Some(s), @@ -866,7 +868,7 @@ impl Bson { } } - /// If `Bson` is `Array`, return its value. Returns `None` otherwise + /// If `self` is [`Array`](Bson::Array), return its value. Returns [`None`] otherwise. pub fn as_array(&self) -> Option<&Array> { match *self { Bson::Array(ref v) => Some(v), @@ -874,7 +876,8 @@ impl Bson { } } - /// If `Bson` is `Array`, return a mutable reference to its value. Returns `None` otherwise + /// If `self` is [`Array`](Bson::Array), return a mutable reference to its value. Returns + /// [`None`] otherwise. pub fn as_array_mut(&mut self) -> Option<&mut Array> { match *self { Bson::Array(ref mut v) => Some(v), @@ -882,7 +885,7 @@ impl Bson { } } - /// If `Bson` is `Document`, return its value. Returns `None` otherwise + /// If `self` is [`Document`](Bson::Document), return its value. Returns [`None`] otherwise. pub fn as_document(&self) -> Option<&Document> { match *self { Bson::Document(ref v) => Some(v), @@ -890,7 +893,8 @@ impl Bson { } } - /// If `Bson` is `Document`, return a mutable reference to its value. Returns `None` otherwise + /// If `self` is [`Document`](Bson::Document), return a mutable reference to its value. Returns + /// [`None`] otherwise. pub fn as_document_mut(&mut self) -> Option<&mut Document> { match *self { Bson::Document(ref mut v) => Some(v), @@ -898,7 +902,7 @@ impl Bson { } } - /// If `Bson` is `Bool`, return its value. Returns `None` otherwise + /// If `self` is [`Boolean`](Bson::Boolean), return its value. Returns [`None`] otherwise. pub fn as_bool(&self) -> Option { match *self { Bson::Boolean(v) => Some(v), @@ -906,7 +910,7 @@ impl Bson { } } - /// If `Bson` is `I32`, return its value. Returns `None` otherwise + /// If `self` is [`Int32`](Bson::Int32), return its value. Returns [`None`] otherwise. pub fn as_i32(&self) -> Option { match *self { Bson::Int32(v) => Some(v), @@ -914,7 +918,7 @@ impl Bson { } } - /// If `Bson` is `I64`, return its value. Returns `None` otherwise + /// If `self` is [`Int64`](Bson::Int64), return its value. Returns [`None`] otherwise. pub fn as_i64(&self) -> Option { match *self { Bson::Int64(v) => Some(v), @@ -922,7 +926,7 @@ impl Bson { } } - /// If `Bson` is `Objectid`, return its value. Returns `None` otherwise + /// If `self` is [`ObjectId`](Bson::ObjectId), return its value. Returns [`None`] otherwise. pub fn as_object_id(&self) -> Option { match *self { Bson::ObjectId(v) => Some(v), @@ -930,7 +934,8 @@ impl Bson { } } - /// If `Bson` is `Objectid`, return a mutable reference to its value. Returns `None` otherwise + /// If `self` is [`ObjectId`](Bson::ObjectId), return a mutable reference to its value. Returns + /// [`None`] otherwise. pub fn as_object_id_mut(&mut self) -> Option<&mut oid::ObjectId> { match *self { Bson::ObjectId(ref mut v) => Some(v), @@ -938,7 +943,7 @@ impl Bson { } } - /// If `Bson` is `DateTime`, return its value. Returns `None` otherwise + /// If `self` is [`DateTime`](Bson::DateTime), return its value. Returns [`None`] otherwise. pub fn as_datetime(&self) -> Option<&crate::DateTime> { match *self { Bson::DateTime(ref v) => Some(v), @@ -946,8 +951,8 @@ impl Bson { } } - /// If `Bson` is `DateTime`, return a mutable reference to its value. Returns `None` - /// otherwise + /// If `self` is [`DateTime`](Bson::DateTime), return a mutable reference to its value. Returns + /// [`None`] otherwise. pub fn as_datetime_mut(&mut self) -> Option<&mut crate::DateTime> { match *self { Bson::DateTime(ref mut v) => Some(v), @@ -955,7 +960,7 @@ impl Bson { } } - /// If `Bson` is `Symbol`, return its value. Returns `None` otherwise + /// If `self` is [`Symbol`](Bson::Symbol), return its value. Returns [`None`] otherwise. pub fn as_symbol(&self) -> Option<&str> { match *self { Bson::Symbol(ref v) => Some(v), @@ -963,7 +968,8 @@ impl Bson { } } - /// If `Bson` is `Symbol`, return a mutable reference to its value. Returns `None` otherwise + /// If `self` is [`Symbol`](Bson::Symbol), return a mutable reference to its value. Returns + /// [`None`] otherwise. pub fn as_symbol_mut(&mut self) -> Option<&mut str> { match *self { Bson::Symbol(ref mut v) => Some(v), @@ -971,7 +977,7 @@ impl Bson { } } - /// If `Bson` is `Timestamp`, return its value. Returns `None` otherwise + /// If `self` is [`Timestamp`](Bson::Timestamp), return its value. Returns [`None`] otherwise. pub fn as_timestamp(&self) -> Option { match *self { Bson::Timestamp(timestamp) => Some(timestamp), @@ -979,7 +985,7 @@ impl Bson { } } - /// If `Bson` is `Null`, return its value. Returns `None` otherwise + /// If `self` is [`Null`](Bson::Null), return `()`. Returns [`None`] otherwise. pub fn as_null(&self) -> Option<()> { match *self { Bson::Null => Some(()), @@ -987,6 +993,7 @@ impl Bson { } } + /// If `self` is [`DbPointer`](Bson::DbPointer), return its value. Returns [`None`] otherwise. pub fn as_db_pointer(&self) -> Option<&DbPointer> { match self { Bson::DbPointer(ref db_pointer) => Some(db_pointer), diff --git a/src/datetime.rs b/src/datetime.rs index d212f7a2..8f8b7fee 100644 --- a/src/datetime.rs +++ b/src/datetime.rs @@ -87,10 +87,10 @@ use serde_with::{DeserializeAs, SerializeAs}; /// ## The `serde_with` feature flag /// /// The `serde_with` feature can be enabled to support more ergonomic serde attributes for -/// (de)serializing `chrono::DateTime` from/to BSON via the [`serde_with`](https://docs.rs/serde_with/1.11.0/serde_with/) +/// (de)serializing [`chrono::DateTime`] from/to BSON via the [`serde_with`](https://docs.rs/serde_with/1.11.0/serde_with/) /// crate. The main benefit of this compared to the regular `serde_helpers` is that `serde_with` can -/// handle nested `chrono::DateTime` values (e.g. in `Option`), whereas the former only works on -/// fields that are exactly `chrono::DateTime`. +/// handle nested [`chrono::DateTime`] values (e.g. in [`Option`]), whereas the former only works on +/// fields that are exactly [`chrono::DateTime`]. /// ``` /// # #[cfg(all(feature = "chrono-0_4", feature = "serde_with"))] /// # { @@ -100,7 +100,7 @@ use serde_with::{DeserializeAs, SerializeAs}; /// #[serde_with::serde_as] /// #[derive(Deserialize, Serialize, PartialEq, Debug)] /// struct Foo { -/// /// Serializes as a BSON datetime rather than using `chrono::DateTime`'s serialization +/// /// Serializes as a BSON datetime rather than using [`chrono::DateTime`]'s serialization /// #[serde_as(as = "Option")] /// as_bson: Option>, /// } @@ -139,8 +139,8 @@ impl crate::DateTime { Self::from_system_time(SystemTime::now()) } - /// Convert the given `chrono::DateTime` into a `bson::DateTime`, truncating it to millisecond - /// precision. + /// Convert the given [`chrono::DateTime`] into a [`bson::DateTime`](DateTime), truncating it to + /// millisecond precision. #[cfg(feature = "chrono-0_4")] #[cfg_attr(docsrs, doc(cfg(feature = "chrono-0_4")))] pub fn from_chrono(dt: chrono::DateTime) -> Self { @@ -206,8 +206,8 @@ impl crate::DateTime { Self::from_time_private(dt) } - /// Convert the given `time::OffsetDateTime` into a `bson::DateTime`, truncating it to - /// millisecond precision. + /// Convert the given [`time::OffsetDateTime`] into a [`bson::DateTime`](DateTime), truncating + /// it to millisecond precision. /// /// If the provided time is too far in the future or too far in the past to be represented /// by a BSON datetime, either [`DateTime::MAX`] or [`DateTime::MIN`] will be @@ -455,7 +455,7 @@ pub enum Error { /// Error returned when an invalid datetime format is provided to a conversion method. #[non_exhaustive] InvalidTimestamp { message: String }, - /// Error returned when a `DateTime` cannot be represented in a particular format. + /// Error returned when a [`DateTime`] cannot be represented in a particular format. #[non_exhaustive] CannotFormat { message: String }, } diff --git a/src/de/error.rs b/src/de/error.rs index 7aee0680..30d4f51a 100644 --- a/src/de/error.rs +++ b/src/de/error.rs @@ -15,8 +15,8 @@ pub enum Error { /// while decoding a UTF-8 String from the input data. InvalidUtf8String(string::FromUtf8Error), - /// While decoding a `Document` from bytes, an unexpected or unsupported element type was - /// encountered. + /// While decoding a [`Document`](crate::Document) from bytes, an unexpected or unsupported + /// element type was encountered. #[non_exhaustive] UnrecognizedDocumentElementType { /// The key at which an unexpected/unsupported element type was encountered. @@ -91,7 +91,8 @@ impl de::Error for Error { pub type Result = std::result::Result; impl Bson { - /// Method for converting a given `Bson` value to a `serde::de::Unexpected` for error reporting. + /// Method for converting a given [`Bson`] value to a [`serde::de::Unexpected`] for error + /// reporting. pub(crate) fn as_unexpected(&self) -> Unexpected { match self { Bson::Array(_) => Unexpected::Seq, diff --git a/src/de/mod.rs b/src/de/mod.rs index 05b3214b..909b71cd 100644 --- a/src/de/mod.rs +++ b/src/de/mod.rs @@ -65,11 +65,11 @@ enum DeserializerHint { None, /// The type being deserialized expects the BSON to contain a binary value with the provided - /// subtype. This is currently used to deserialize `bson::Uuid` values. + /// subtype. This is currently used to deserialize [`bson::Uuid`] values. BinarySubtype(BinarySubtype), /// The type being deserialized is raw BSON, meaning no allocations should occur as part of - /// deserializing and everything should be visited via borrowing or `Copy` if possible. + /// deserializing and everything should be visited via borrowing or [`Copy`] if possible. RawBson, } @@ -433,7 +433,7 @@ impl JavaScriptCodeWithScope { /// Deserialize a `T` from the provided [`Bson`] value. /// -/// The `Deserializer` used by this function presents itself as human readable, whereas the +/// The [`Deserializer`] used by this function presents itself as human readable, whereas the /// one used in [`from_slice`] does not. This means that this function may deserialize differently /// than [`from_slice`] for types that change their deserialization logic depending on whether /// the format is human readable or not. To deserialize from [`Bson`] with a deserializer that @@ -473,7 +473,7 @@ where /// Deserialize a `T` from the provided [`Document`]. /// -/// The `Deserializer` used by this function presents itself as human readable, whereas the +/// The [`Deserializer`] used by this function presents itself as human readable, whereas the /// one used in [`from_slice`] does not. This means that this function may deserialize differently /// than [`from_slice`] for types that change their deserialization logic depending on whether /// the format is human readable or not. To deserialize from [`Document`] with a deserializer that diff --git a/src/de/raw.rs b/src/de/raw.rs index 51842782..a5ef20c1 100644 --- a/src/de/raw.rs +++ b/src/de/raw.rs @@ -129,7 +129,7 @@ impl<'de> Deserializer<'de> { /// /// If hinted to use raw BSON, the bytes themselves will be visited using a special newtype /// name. Otherwise, the key-value pairs will be accessed in order, either as part of a - /// `MapAccess` for documents or a `SeqAccess` for arrays. + /// [`MapAccess`] for documents or a [`SeqAccess`] for arrays. fn deserialize_document( &mut self, visitor: V, @@ -165,7 +165,7 @@ impl<'de> Deserializer<'de> { } } - /// Construct a `DocumentAccess` and pass it into the provided closure, returning the + /// Construct a [`DocumentAccess`] and pass it into the provided closure, returning the /// result of the closure if no other errors are encountered. fn access_document(&mut self, f: F) -> Result where @@ -188,7 +188,7 @@ impl<'de> Deserializer<'de> { } /// Deserialize the next element type and update `current_type` accordingly. - /// Returns `None` if a null byte is read. + /// Returns [`None`] if a null byte is read. fn deserialize_next_type(&mut self) -> Result> { let tag = read_u8(&mut self.bytes)?; if tag == 0 { @@ -505,7 +505,7 @@ impl<'d, 'de> DocumentAccess<'d, 'de> { /// Executes a closure that reads from the BSON bytes and returns an error if the number of /// bytes read exceeds length_remaining. /// - /// A mutable reference to this `DocumentAccess` is passed into the closure. + /// A mutable reference to this [`DocumentAccess`] is passed into the closure. fn read(&mut self, f: F) -> Result where F: FnOnce(&mut Self) -> Result, @@ -711,7 +711,7 @@ impl<'de> serde::de::Deserializer<'de> for FieldDeserializer { } } -/// A `MapAccess` used to deserialize entire documents as chunks of bytes without deserializing +/// A [`MapAccess`] used to deserialize entire documents as chunks of bytes without deserializing /// the individual key/value pairs. struct RawDocumentAccess<'d> { deserializer: RawDocumentDeserializer<'d>, @@ -751,7 +751,7 @@ impl<'de> serde::de::MapAccess<'de> for RawDocumentAccess<'de> { if !self.deserialized_first { self.deserialized_first = true; - // the newtype name will indicate to the `RawBson` enum that the incoming + // the newtype name will indicate to the [`RawBson`] enum that the incoming // bytes are meant to be treated as a document or array instead of a binary value. seed.deserialize(FieldDeserializer { field_name: if self.array { @@ -1027,7 +1027,7 @@ impl<'de, 'a> serde::de::Deserializer<'de> for &'a mut TimestampDeserializer { } } -/// A `MapAccess` providing access to a BSON datetime being deserialized. +/// A [`MapAccess`] providing access to a BSON datetime being deserialized. /// /// If hinted to be raw BSON, this deserializes the serde data model equivalent /// of { "$date": }. @@ -1136,7 +1136,7 @@ impl<'de, 'a> serde::de::Deserializer<'de> for &'a mut DateTimeDeserializer { } } -/// A `MapAccess` providing access to a BSON binary being deserialized. +/// A [`MapAccess`] providing access to a BSON binary being deserialized. /// /// If hinted to be raw BSON, this deserializes the serde data model equivalent /// of { "$binary": { "subType": , "bytes": } }. @@ -1241,7 +1241,7 @@ enum BinaryDeserializationStage { Done, } -/// A `MapAccess` providing access to a BSON code with scope being deserialized. +/// A [`MapAccess`] providing access to a BSON code with scope being deserialized. /// /// If hinted to be raw BSON, this deserializes the serde data model equivalent /// of { "$code": , "$scope": <&RawDocument> } }. @@ -1308,7 +1308,7 @@ impl<'de, 'a> CodeWithScopeDeserializer<'de, 'a> { /// Executes a closure that reads from the BSON bytes and returns an error if the number of /// bytes read exceeds length_remaining. /// - /// A mutable reference to this `CodeWithScopeDeserializer` is passed into the closure. + /// A mutable reference to this [`CodeWithScopeDeserializer`] is passed into the closure. fn read(&mut self, f: F) -> Result where F: FnOnce(&mut Self) -> Result, @@ -1381,7 +1381,7 @@ enum CodeWithScopeDeserializationStage { Done, } -/// A `MapAccess` providing access to a BSON DB pointer being deserialized. +/// A [`MapAccess`] providing access to a BSON DB pointer being deserialized. /// /// Regardless of the hint, this deserializes the serde data model equivalent /// of { "$dbPointer": { "$ref": , "$id": } }. @@ -1498,7 +1498,7 @@ enum DbPointerDeserializationStage { Done, } -/// A `MapAccess` providing access to a BSON regular expression being deserialized. +/// A [`MapAccess`] providing access to a BSON regular expression being deserialized. /// /// Regardless of the hint, this deserializes the serde data model equivalent /// of { "$regularExpression": { "pattern": , "options": } }. @@ -1773,7 +1773,7 @@ impl<'a> BsonBuf<'a> { /// Attempts to read a null-terminated UTF-8 cstring from the data. /// /// If utf8_lossy and invalid UTF-8 is encountered, the unicode replacement character will be - /// inserted in place of the offending data, resulting in an owned `String`. Otherwise, the + /// inserted in place of the offending data, resulting in an owned [`String`]. Otherwise, the /// data will be borrowed as-is. fn read_cstr(&mut self) -> Result> { let start = self.index; @@ -1807,7 +1807,7 @@ impl<'a> BsonBuf<'a> { /// Attempts to read a null-terminated UTF-8 string from the data. /// /// If invalid UTF-8 is encountered, the unicode replacement character will be inserted in place - /// of the offending data, resulting in an owned `String`. Otherwise, the data will be + /// of the offending data, resulting in an owned [`String`]. Otherwise, the data will be /// borrowed as-is. fn read_str(&mut self) -> Result> { let start = self._advance_to_len_encoded_str()?; diff --git a/src/de/serde.rs b/src/de/serde.rs index 3045f643..8181b677 100644 --- a/src/de/serde.rs +++ b/src/de/serde.rs @@ -101,7 +101,7 @@ impl<'de> Deserialize<'de> for ObjectId { } impl<'de> Deserialize<'de> for Document { - /// Deserialize this value given this `Deserializer`. + /// Deserialize this value given this [`Deserializer`]. fn deserialize(deserializer: D) -> Result where D: de::Deserializer<'de>, diff --git a/src/document.rs b/src/document.rs index b8d1600c..f27e923d 100644 --- a/src/document.rs +++ b/src/document.rs @@ -118,7 +118,7 @@ pub struct Values<'a> { inner: indexmap::map::Values<'a, String, Bson>, } -/// An iterator over a `Document`'s keys and mutable values. +/// An iterator over a [`Document`]'s keys and mutable values. pub struct IterMut<'a> { inner: indexmap::map::IterMut<'a, String, Bson>, } @@ -526,10 +526,10 @@ impl Document { } } - /// Attempts to serialize the `Document` into a byte stream. + /// Attempts to serialize the [`Document`] into a byte stream. /// /// While the method signature indicates an owned writer must be passed in, a mutable reference - /// may also be passed in due to blanket implementations of `Write` provided in the standard + /// may also be passed in due to blanket implementations of [`Write`] provided in the standard /// library. /// /// ``` @@ -592,10 +592,10 @@ impl Document { Ok(doc) } - /// Attempts to deserialize a `Document` from a byte stream. + /// Attempts to deserialize a [`Document`] from a byte stream. /// /// While the method signature indicates an owned reader must be passed in, a mutable reference - /// may also be passed in due to blanket implementations of `Read` provided in the standard + /// may also be passed in due to blanket implementations of [`Read`] provided in the standard /// library. /// /// ``` @@ -624,7 +624,7 @@ impl Document { Self::decode(&mut reader, false) } - /// Attempt to deserialize a `Document` that may contain invalid UTF-8 strings from a byte + /// Attempt to deserialize a [`Document`] that may contain invalid UTF-8 strings from a byte /// stream. /// /// This is mainly useful when reading raw BSON returned from a MongoDB server, which diff --git a/src/lib.rs b/src/lib.rs index 9e17cffe..17dc6435 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -183,7 +183,7 @@ //! phones: Vec, //! } //! -//! // Some BSON input data as a `Bson`. +//! // Some BSON input data as a [`Bson`]. //! let bson_data: Bson = bson!({ //! "name": "John Doe", //! "age": 43, @@ -202,11 +202,11 @@ //! println!("Redacting {}'s record.", person.name); //! person.name = "REDACTED".to_string(); //! -//! // Get a serialized version of the input data as a `Bson`. +//! // Get a serialized version of the input data as a [`Bson`]. //! let redacted_bson = bson::to_bson(&person).unwrap(); //! ``` //! -//! Any types that implement `Serialize` and `Deserialize` can be used in this way. Doing so helps +//! Any types that implement [`Serialize`](serde::Serialize) and [`Deserialize`](serde::Deserialize) can be used in this way. Doing so helps //! separate the "business logic" that operates over the data from the (de)serialization logic that //! translates the data to/from its serialized form. This can lead to more clear and concise code //! that is also less error prone. @@ -215,15 +215,15 @@ //! //! The BSON format includes a datetime type, which is modeled in this crate by the //! [`DateTime`] struct, and the -//! `Serialize` and `Deserialize` implementations for this struct produce and parse BSON datetimes +//! [`Serialize`](serde::Serialize) and [`Deserialize`](serde::Deserialize) implementations for this struct produce and parse BSON datetimes //! when serializing to or deserializing from BSON. The popular crate [`chrono`](docs.rs/chrono) -//! also provides a `DateTime` type, but its `Serialize` and `Deserialize` implementations operate +//! also provides a [`DateTime`] type, but its [`Serialize`](serde::Serialize) and [`Deserialize`](serde::Deserialize) implementations operate //! on strings instead, so when using it with BSON, the BSON datetime type is not used. To work //! around this, the `chrono-0_4` feature flag can be enabled. This flag exposes a number of -//! convenient conversions between `bson::DateTime` and `chrono::DateTime`, including the +//! convenient conversions between [`bson::DateTime`](crate::DateTime) and [`chrono::DateTime`], including the //! [`serde_helpers::chrono_datetime_as_bson_datetime`] -//! serde helper, which can be used to (de)serialize `chrono::DateTime`s to/from BSON datetimes, and -//! the `From` implementation for [`Bson`], which allows `chrono::DateTime` values +//! serde helper, which can be used to (de)serialize [`chrono::DateTime`]s to/from BSON datetimes, and +//! the `From` implementation for [`Bson`], which allows [`chrono::DateTime`] values //! to be used in the `doc!` and `bson!` macros. //! //! e.g. diff --git a/src/raw/array_buf.rs b/src/raw/array_buf.rs index 3c389d1f..fa696783 100644 --- a/src/raw/array_buf.rs +++ b/src/raw/array_buf.rs @@ -12,7 +12,7 @@ use super::{bson::RawBson, serde::OwnedOrBorrowedRawArray, RawArrayIter}; /// An owned BSON array value (akin to [`std::path::PathBuf`]), backed by a buffer of raw BSON /// bytes. This type can be used to construct owned array values, which can be used to append to -/// [`RawDocumentBuf`] or as a field in a `Deserialize` struct. +/// [`RawDocumentBuf`] or as a field in a [`Deserialize`] struct. /// /// Iterating over a [`RawArrayBuf`] yields either an error or a [`RawBson`] value that borrows from /// the original document without making any additional allocations. @@ -36,11 +36,11 @@ use super::{bson::RawBson, serde::OwnedOrBorrowedRawArray, RawArrayIter}; /// # Ok::<(), Error>(()) /// ``` /// -/// This type implements `Deref` to [`RawArray`], meaning that all methods on [`RawArray`] are -/// available on [`RawArrayBuf`] values as well. This includes [`RawArray::get`] or any of the -/// type-specific getters, such as [`RawArray::get_object_id`] or [`RawArray::get_str`]. Note -/// that accessing elements is an O(N) operation, as it requires iterating through the document from -/// the beginning to find the requested key. +/// This type implements [`Deref`](std::ops::Deref) to [`RawArray`], meaning that all methods on +/// [`RawArray`] are available on [`RawArrayBuf`] values as well. This includes [`RawArray::get`] or +/// any of the type-specific getters, such as [`RawArray::get_object_id`] or [`RawArray::get_str`]. +/// Note that accessing elements is an O(N) operation, as it requires iterating through the document +/// from the beginning to find the requested key. #[derive(Clone, PartialEq)] pub struct RawArrayBuf { inner: RawDocumentBuf, @@ -48,7 +48,7 @@ pub struct RawArrayBuf { } impl RawArrayBuf { - /// Construct a new, empty `RawArrayBuf`. + /// Construct a new, empty [`RawArrayBuf`]. pub fn new() -> RawArrayBuf { Self { inner: RawDocumentBuf::new(), @@ -56,7 +56,7 @@ impl RawArrayBuf { } } - /// Construct a new `RawArrayBuf` from the provided `Vec` of bytes. + /// Construct a new [`RawArrayBuf`] from the provided [`Vec`] of bytes. /// /// This involves a traversal of the array to count the values. pub(crate) fn from_raw_document_buf(doc: RawDocumentBuf) -> Self { diff --git a/src/raw/bson.rs b/src/raw/bson.rs index 9db28505..c216c8fd 100644 --- a/src/raw/bson.rs +++ b/src/raw/bson.rs @@ -104,7 +104,7 @@ impl RawBson { } } - /// Gets the wrapped `f64` value or returns `None` if the value isn't a BSON + /// Gets the wrapped `f64` value or returns [`None`] if the value isn't a BSON /// double. pub fn as_f64(&self) -> Option { match self { @@ -113,8 +113,8 @@ impl RawBson { } } - /// Gets a reference to the `String` that's wrapped or returns `None` if the wrapped value isn't - /// a BSON String. + /// Gets a reference to the [`String`] that's wrapped or returns [`None`] if the wrapped value + /// isn't a BSON String. pub fn as_str(&self) -> Option<&'_ str> { match self { RawBson::String(s) => Some(s), @@ -122,7 +122,7 @@ impl RawBson { } } - /// Gets a reference to the [`RawArrayBuf`] that's wrapped or returns `None` if the wrapped + /// Gets a reference to the [`RawArrayBuf`] that's wrapped or returns [`None`] if the wrapped /// value isn't a BSON array. pub fn as_array(&self) -> Option<&'_ RawArray> { match self { @@ -131,7 +131,7 @@ impl RawBson { } } - /// Gets a mutable reference to the [`RawArrayBuf`] that's wrapped or returns `None` if the + /// Gets a mutable reference to the [`RawArrayBuf`] that's wrapped or returns [`None`] if the /// wrapped value isn't a BSON array. pub fn as_array_mut(&mut self) -> Option<&mut RawArrayBuf> { match self { @@ -140,7 +140,7 @@ impl RawBson { } } - /// Gets a reference to the [`RawDocumentBuf`] that's wrapped or returns `None` if the wrapped + /// Gets a reference to the [`RawDocumentBuf`] that's wrapped or returns [`None`] if the wrapped /// value isn't a BSON document. pub fn as_document(&self) -> Option<&'_ RawDocument> { match self { @@ -149,7 +149,7 @@ impl RawBson { } } - /// Gets a mutable reference to the [`RawDocumentBuf`] that's wrapped or returns `None` if the + /// Gets a mutable reference to the [`RawDocumentBuf`] that's wrapped or returns [`None`] if the /// wrapped value isn't a BSON document. pub fn as_document_mut(&mut self) -> Option<&mut RawDocumentBuf> { match self { @@ -158,7 +158,7 @@ impl RawBson { } } - /// Gets the wrapped `bool` value or returns `None` if the wrapped value isn't a BSON + /// Gets the wrapped `bool` value or returns [`None`] if the wrapped value isn't a BSON /// boolean. pub fn as_bool(&self) -> Option { match self { @@ -167,7 +167,7 @@ impl RawBson { } } - /// Gets the wrapped `i32` value or returns `None` if the wrapped value isn't a BSON + /// Gets the wrapped `i32` value or returns [`None`] if the wrapped value isn't a BSON /// Int32. pub fn as_i32(&self) -> Option { match self { @@ -176,7 +176,7 @@ impl RawBson { } } - /// Gets the wrapped `i64` value or returns `None` if the wrapped value isn't a BSON + /// Gets the wrapped `i64` value or returns [`None`] if the wrapped value isn't a BSON /// Int64. pub fn as_i64(&self) -> Option { match self { @@ -185,8 +185,8 @@ impl RawBson { } } - /// Gets the wrapped [`crate::oid::ObjectId`] value or returns `None` if the wrapped value isn't - /// a BSON ObjectID. + /// Gets the wrapped [`crate::oid::ObjectId`] value or returns [`None`] if the wrapped value + /// isn't a BSON ObjectID. pub fn as_object_id(&self) -> Option { match self { RawBson::ObjectId(v) => Some(*v), @@ -194,7 +194,7 @@ impl RawBson { } } - /// Gets a reference to the [`Binary`] that's wrapped or returns `None` if the wrapped value + /// Gets a reference to the [`Binary`] that's wrapped or returns [`None`] if the wrapped value /// isn't a BSON binary. pub fn as_binary(&self) -> Option> { match self { @@ -206,7 +206,7 @@ impl RawBson { } } - /// Gets a reference to the [`Regex`] that's wrapped or returns `None` if the wrapped value + /// Gets a reference to the [`Regex`] that's wrapped or returns [`None`] if the wrapped value /// isn't a BSON regular expression. pub fn as_regex(&self) -> Option> { match self { @@ -218,7 +218,7 @@ impl RawBson { } } - /// Gets the wrapped [`crate::DateTime`] value or returns `None` if the wrapped value isn't a + /// Gets the wrapped [`crate::DateTime`] value or returns [`None`] if the wrapped value isn't a /// BSON datetime. pub fn as_datetime(&self) -> Option { match self { @@ -227,8 +227,8 @@ impl RawBson { } } - /// Gets a reference to the symbol that's wrapped or returns `None` if the wrapped value isn't a - /// BSON Symbol. + /// Gets a reference to the symbol that's wrapped or returns [`None`] if the wrapped value isn't + /// a BSON Symbol. pub fn as_symbol(&self) -> Option<&'_ str> { match self { RawBson::Symbol(v) => Some(v), @@ -236,7 +236,7 @@ impl RawBson { } } - /// Gets the wrapped [`crate::Timestamp`] value or returns `None` if the wrapped value isn't a + /// Gets the wrapped [`crate::Timestamp`] value or returns [`None`] if the wrapped value isn't a /// BSON datetime. pub fn as_timestamp(&self) -> Option { match self { @@ -245,7 +245,7 @@ impl RawBson { } } - /// Returns `Some(())` if this value is null, otherwise returns `None`. + /// Returns `Some(())` if this value is null, otherwise returns [`None`]. pub fn as_null(&self) -> Option<()> { match self { RawBson::Null => Some(()), @@ -253,8 +253,8 @@ impl RawBson { } } - /// Gets a reference to the [`crate::DbPointer`] that's wrapped or returns `None` if the wrapped - /// value isn't a BSON DbPointer. + /// Gets a reference to the [`crate::DbPointer`] that's wrapped or returns [`None`] if the + /// wrapped value isn't a BSON DbPointer. pub fn as_db_pointer(&self) -> Option> { match self { RawBson::DbPointer(d) => Some(RawDbPointerRef { @@ -265,7 +265,7 @@ impl RawBson { } } - /// Gets a reference to the code that's wrapped or returns `None` if the wrapped value isn't a + /// Gets a reference to the code that's wrapped or returns [`None`] if the wrapped value isn't a /// BSON JavaScript code. pub fn as_javascript(&self) -> Option<&'_ str> { match self { @@ -274,7 +274,7 @@ impl RawBson { } } - /// Gets a reference to the [`RawJavaScriptCodeWithScope`] that's wrapped or returns `None` + /// Gets a reference to the [`RawJavaScriptCodeWithScope`] that's wrapped or returns [`None`] /// if the wrapped value isn't a BSON JavaScript code with scope value. pub fn as_javascript_with_scope(&self) -> Option> { match self { diff --git a/src/raw/bson_ref.rs b/src/raw/bson_ref.rs index a0668e01..4af7eb45 100644 --- a/src/raw/bson_ref.rs +++ b/src/raw/bson_ref.rs @@ -101,7 +101,7 @@ impl<'a> RawBsonRef<'a> { } } - /// Gets the `f64` that's referenced or returns `None` if the referenced value isn't a BSON + /// Gets the `f64` that's referenced or returns [`None`] if the referenced value isn't a BSON /// double. pub fn as_f64(self) -> Option { match self { @@ -110,7 +110,7 @@ impl<'a> RawBsonRef<'a> { } } - /// Gets the `&str` that's referenced or returns `None` if the referenced value isn't a BSON + /// Gets the `&str` that's referenced or returns [`None`] if the referenced value isn't a BSON /// String. pub fn as_str(self) -> Option<&'a str> { match self { @@ -119,7 +119,7 @@ impl<'a> RawBsonRef<'a> { } } - /// Gets the [`RawArray`] that's referenced or returns `None` if the referenced value + /// Gets the [`RawArray`] that's referenced or returns [`None`] if the referenced value /// isn't a BSON array. pub fn as_array(self) -> Option<&'a RawArray> { match self { @@ -128,7 +128,7 @@ impl<'a> RawBsonRef<'a> { } } - /// Gets the [`RawDocument`] that's referenced or returns `None` if the referenced value + /// Gets the [`RawDocument`] that's referenced or returns [`None`] if the referenced value /// isn't a BSON document. pub fn as_document(self) -> Option<&'a RawDocument> { match self { @@ -137,7 +137,7 @@ impl<'a> RawBsonRef<'a> { } } - /// Gets the `bool` that's referenced or returns `None` if the referenced value isn't a BSON + /// Gets the `bool` that's referenced or returns [`None`] if the referenced value isn't a BSON /// boolean. pub fn as_bool(self) -> Option { match self { @@ -146,7 +146,7 @@ impl<'a> RawBsonRef<'a> { } } - /// Gets the `i32` that's referenced or returns `None` if the referenced value isn't a BSON + /// Gets the `i32` that's referenced or returns [`None`] if the referenced value isn't a BSON /// Int32. pub fn as_i32(self) -> Option { match self { @@ -155,7 +155,7 @@ impl<'a> RawBsonRef<'a> { } } - /// Gets the `i64` that's referenced or returns `None` if the referenced value isn't a BSON + /// Gets the `i64` that's referenced or returns [`None`] if the referenced value isn't a BSON /// Int64. pub fn as_i64(self) -> Option { match self { @@ -164,7 +164,7 @@ impl<'a> RawBsonRef<'a> { } } - /// Gets the [`crate::oid::ObjectId`] that's referenced or returns `None` if the referenced + /// Gets the [`crate::oid::ObjectId`] that's referenced or returns [`None`] if the referenced /// value isn't a BSON ObjectID. pub fn as_object_id(self) -> Option { match self { @@ -173,8 +173,8 @@ impl<'a> RawBsonRef<'a> { } } - /// Gets the [`RawBinaryRef`] that's referenced or returns `None` if the referenced value isn't - /// a BSON binary. + /// Gets the [`RawBinaryRef`] that's referenced or returns [`None`] if the referenced value + /// isn't a BSON binary. pub fn as_binary(self) -> Option> { match self { RawBsonRef::Binary(v) => Some(v), @@ -182,8 +182,8 @@ impl<'a> RawBsonRef<'a> { } } - /// Gets the [`RawRegexRef`] that's referenced or returns `None` if the referenced value isn't a - /// BSON regular expression. + /// Gets the [`RawRegexRef`] that's referenced or returns [`None`] if the referenced value isn't + /// a BSON regular expression. pub fn as_regex(self) -> Option> { match self { RawBsonRef::RegularExpression(v) => Some(v), @@ -191,7 +191,7 @@ impl<'a> RawBsonRef<'a> { } } - /// Gets the [`crate::DateTime`] that's referenced or returns `None` if the referenced value + /// Gets the [`crate::DateTime`] that's referenced or returns [`None`] if the referenced value /// isn't a BSON datetime. pub fn as_datetime(self) -> Option { match self { @@ -200,7 +200,7 @@ impl<'a> RawBsonRef<'a> { } } - /// Gets the symbol that's referenced or returns `None` if the referenced value isn't a BSON + /// Gets the symbol that's referenced or returns [`None`] if the referenced value isn't a BSON /// symbol. pub fn as_symbol(self) -> Option<&'a str> { match self { @@ -209,7 +209,7 @@ impl<'a> RawBsonRef<'a> { } } - /// Gets the [`crate::Timestamp`] that's referenced or returns `None` if the referenced value + /// Gets the [`crate::Timestamp`] that's referenced or returns [`None`] if the referenced value /// isn't a BSON timestamp. pub fn as_timestamp(self) -> Option { match self { @@ -218,8 +218,8 @@ impl<'a> RawBsonRef<'a> { } } - /// Gets the null value that's referenced or returns `None` if the referenced value isn't a BSON - /// null. + /// Gets the null value that's referenced or returns [`None`] if the referenced value isn't a + /// BSON null. pub fn as_null(self) -> Option<()> { match self { RawBsonRef::Null => Some(()), @@ -227,7 +227,7 @@ impl<'a> RawBsonRef<'a> { } } - /// Gets the [`RawDbPointerRef`] that's referenced or returns `None` if the referenced value + /// Gets the [`RawDbPointerRef`] that's referenced or returns [`None`] if the referenced value /// isn't a BSON DB pointer. pub fn as_db_pointer(self) -> Option> { match self { @@ -236,7 +236,7 @@ impl<'a> RawBsonRef<'a> { } } - /// Gets the code that's referenced or returns `None` if the referenced value isn't a BSON + /// Gets the code that's referenced or returns [`None`] if the referenced value isn't a BSON /// JavaScript. pub fn as_javascript(self) -> Option<&'a str> { match self { @@ -245,7 +245,7 @@ impl<'a> RawBsonRef<'a> { } } - /// Gets the [`RawJavaScriptCodeWithScope`] that's referenced or returns `None` if the + /// Gets the [`RawJavaScriptCodeWithScope`] that's referenced or returns [`None`] if the /// referenced value isn't a BSON JavaScript with scope. pub fn as_javascript_with_scope(self) -> Option> { match self { @@ -460,7 +460,7 @@ pub struct RawBinaryRef<'a> { } impl<'a> RawBinaryRef<'a> { - /// Copy the contents into a `Binary`. + /// Copy the contents into a [`Binary`]. pub fn to_binary(&self) -> Binary { Binary { subtype: self.subtype, diff --git a/src/raw/document.rs b/src/raw/document.rs index b5193067..57a42f10 100644 --- a/src/raw/document.rs +++ b/src/raw/document.rs @@ -124,7 +124,7 @@ impl RawDocument { Ok(RawDocument::new_unchecked(data)) } - /// Creates a new `RawDocument` referencing the provided data slice. + /// Creates a new [`RawDocument`] referencing the provided data slice. pub(crate) fn new_unchecked + ?Sized>(data: &D) -> &RawDocument { // SAFETY: // diff --git a/src/raw/document_buf.rs b/src/raw/document_buf.rs index ded704e1..978de443 100644 --- a/src/raw/document_buf.rs +++ b/src/raw/document_buf.rs @@ -49,11 +49,11 @@ use super::{ /// # Ok::<(), Error>(()) /// ``` /// -/// This type implements `Deref` to [`RawDocument`], meaning that all methods on [`RawDocument`] are -/// available on [`RawDocumentBuf`] values as well. This includes [`RawDocument::get`] or any of the -/// type-specific getters, such as [`RawDocument::get_object_id`] or [`RawDocument::get_str`]. Note -/// that accessing elements is an O(N) operation, as it requires iterating through the document from -/// the beginning to find the requested key. +/// This type implements [`Deref`] to [`RawDocument`], meaning that all methods on [`RawDocument`] +/// are available on [`RawDocumentBuf`] values as well. This includes [`RawDocument::get`] or any of +/// the type-specific getters, such as [`RawDocument::get_object_id`] or [`RawDocument::get_str`]. +/// Note that accessing elements is an O(N) operation, as it requires iterating through the document +/// from the beginning to find the requested key. /// /// ``` /// use bson::raw::RawDocumentBuf; diff --git a/src/raw/mod.rs b/src/raw/mod.rs index 3eebc030..ced3f1dd 100644 --- a/src/raw/mod.rs +++ b/src/raw/mod.rs @@ -12,9 +12,9 @@ //! A [`RawDocumentBuf`] can be created from a `Vec` containing raw BSON data. A //! [`RawDocument`] can be created from anything that can be borrowed as a `&[u8]`. Both types //! can access elements via methods similar to those available on the [`crate::Document`] type. -//! Note that [`RawDocument::get`] (which [`RawDocument`] calls through to via its `Deref` -//! implementation) returns a `Result`, since the bytes contained in the document are not fully -//! validated until trying to access the contained data. +//! Note that [`RawDocument::get`] (which [`RawDocument`] calls through to via its +//! [`Deref`](std::ops::Deref) implementation) returns a [`Result`], since the bytes contained in +//! the document are not fully validated until trying to access the contained data. //! //! ```rust //! use bson::raw::{ diff --git a/src/raw/serde.rs b/src/raw/serde.rs index e13ffdd7..ab99ef93 100644 --- a/src/raw/serde.rs +++ b/src/raw/serde.rs @@ -30,8 +30,8 @@ use super::{bson::RawBson, RAW_BSON_NEWTYPE}; /// A raw BSON value that may either be borrowed or owned. /// -/// This is used to consolidate the `Serialize` and `Deserialize` implementations for -/// `RawBson` and `OwnedRawBson`. +/// This is used to consolidate the [`Serialize`] and [`Deserialize`] implementations for +/// [`RawBson`] and [`OwnedRawBson`]. pub(crate) enum OwnedOrBorrowedRawBson<'a> { Owned(RawBson), Borrowed(RawBsonRef<'a>), @@ -68,7 +68,7 @@ impl<'a> From for OwnedOrBorrowedRawBson<'a> { } /// Wrapper around a `Cow` to enable borrowed deserialization. -/// The default `Deserialize` impl for `Cow` always uses the owned version. +/// The default [`Deserialize`] impl for [`Cow`] always uses the owned version. #[derive(Debug, Deserialize)] struct CowStr<'a>(#[serde(borrow)] Cow<'a, str>); diff --git a/src/ser/mod.rs b/src/ser/mod.rs index 8c26ee5a..a15065e8 100644 --- a/src/ser/mod.rs +++ b/src/ser/mod.rs @@ -183,9 +183,9 @@ pub(crate) fn serialize_bson( } } -/// Encode a `T` Serializable into a BSON `Value`. +/// Encode a `T` Serializable into a [`Bson`] value. /// -/// The `Serializer` used by this function presents itself as human readable, whereas the +/// The [`Serializer`] used by this function presents itself as human readable, whereas the /// one used in [`to_vec`] does not. This means that this function will produce different BSON than /// [`to_vec`] for types that change their serialization output depending on whether /// the format is human readable or not. To serialize to a [`Document`] with a serializer that @@ -199,7 +199,7 @@ where value.serialize(ser) } -/// Encode a `T` into a `Bson` value, configuring the underlying serializer with the provided +/// Encode a `T` into a [`Bson`] value, configuring the underlying serializer with the provided /// options. /// ``` /// # use serde::Serialize; @@ -223,9 +223,9 @@ where value.serialize(ser) } -/// Encode a `T` Serializable into a BSON `Document`. +/// Encode a `T` Serializable into a BSON [`Document`]. /// -/// The `Serializer` used by this function presents itself as human readable, whereas the +/// The [`Serializer`] used by this function presents itself as human readable, whereas the /// one used in [`to_vec`] does not. This means that this function will produce different BSON than /// [`to_vec`] for types that change their serialization output depending on whether /// the format is human readable or not. To serialize to a [`Document`] with a serializer that diff --git a/src/ser/raw/document_serializer.rs b/src/ser/raw/document_serializer.rs index c4899cf0..e3eb53ee 100644 --- a/src/ser/raw/document_serializer.rs +++ b/src/ser/raw/document_serializer.rs @@ -42,7 +42,7 @@ impl<'a> DocumentSerializer<'a> { Ok(()) } - /// Serialize a document key to string using `KeySerializer`. + /// Serialize a document key to string using [`KeySerializer`]. fn serialize_doc_key(&mut self, key: &T) -> Result<()> where T: serde::Serialize + ?Sized, diff --git a/src/ser/raw/value_serializer.rs b/src/ser/raw/value_serializer.rs index ad4d0812..6f7b9945 100644 --- a/src/ser/raw/value_serializer.rs +++ b/src/ser/raw/value_serializer.rs @@ -17,7 +17,7 @@ use crate::{ use super::{document_serializer::DocumentSerializer, Serializer}; /// A serializer used specifically for serializing the serde-data-model form of a BSON type (e.g. -/// `Binary`) to raw bytes. +/// [`Binary`]) to raw bytes. pub(crate) struct ValueSerializer<'a> { root_serializer: &'a mut Serializer, state: SerializationStep, diff --git a/src/ser/serde.rs b/src/ser/serde.rs index 1b4b5b43..d4556bb9 100644 --- a/src/ser/serde.rs +++ b/src/ser/serde.rs @@ -151,7 +151,7 @@ impl SerializerOptionsBuilder { } impl Serializer { - /// Construct a new `Serializer`. + /// Construct a new [`Serializer`]. #[allow(clippy::new_without_default)] pub fn new() -> Serializer { Serializer { @@ -159,7 +159,7 @@ impl Serializer { } } - /// Construct a new `Serializer` configured with the provided [`SerializerOptions`]. + /// Construct a new [`Serializer`] configured with the provided [`SerializerOptions`]. pub fn new_with_options(options: SerializerOptions) -> Self { Serializer { options } } @@ -308,7 +308,7 @@ impl ser::Serializer for Serializer { let is_human_readable = self.is_human_readable(); match value.serialize(self)? { Bson::String(s) if is_human_readable => { - // the serializer reports itself as human readable, so `Uuid` will + // the serializer reports itself as human readable, so [`Uuid`] will // serialize itself as a string. let uuid = crate::Uuid::parse_str(s).map_err(Error::custom)?; Ok(Bson::Binary(uuid.into())) diff --git a/src/serde_helpers.rs b/src/serde_helpers.rs index e836d1c0..ae133608 100644 --- a/src/serde_helpers.rs +++ b/src/serde_helpers.rs @@ -417,8 +417,8 @@ pub mod hex_string_as_object_id { } } -/// Contains functions to `serialize` a `i64` integer as `DateTime` and `deserialize` -/// a `i64` integer from `DateTime` +/// Contains functions to `serialize` a `i64` integer as [`DateTime`](crate::DateTime) and +/// `deserialize` a `i64` integer from [`DateTime`](crate::DateTime). /// /// ### The i64 should represent seconds `(DateTime::timestamp_millis(..))`. /// diff --git a/src/spec.rs b/src/spec.rs index 04ac478a..1d2d6853 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -58,7 +58,7 @@ const BINARY_SUBTYPE_USER_DEFINED: u8 = 0x80; /// All available BSON element types. /// -/// Not all element types are representable by the `Bson` type. +/// Not all element types are representable by the [`Bson`](crate::Bson) type. #[repr(u8)] #[derive(Debug, Eq, PartialEq, Clone, Copy)] pub enum ElementType { diff --git a/src/tests/spec/corpus.rs b/src/tests/spec/corpus.rs index ceb1976c..6ded2dd5 100644 --- a/src/tests/spec/corpus.rs +++ b/src/tests/spec/corpus.rs @@ -103,7 +103,7 @@ fn run_test(test: TestFile) { let canonical_bson = hex::decode(&valid.canonical_bson).expect(&description); - // these four cover the four ways to create a `Document` from the provided BSON. + // these four cover the four ways to create a [`Document`] from the provided BSON. let documentfromreader_cb = Document::from_reader(canonical_bson.as_slice()).expect(&description); @@ -133,7 +133,7 @@ fn run_test(test: TestFile) { let canonical_raw_document_from_slice = crate::from_slice::<&RawDocument>(canonical_bson.as_slice()).expect(&description); - // These cover the ways to serialize those `Documents` back to BSON. + // These cover the ways to serialize those [`Documents`] back to BSON. let mut documenttowriter_documentfromreader_cb = Vec::new(); documentfromreader_cb .to_writer(&mut documenttowriter_documentfromreader_cb) diff --git a/src/uuid/mod.rs b/src/uuid/mod.rs index fe658b60..446e57f0 100644 --- a/src/uuid/mod.rs +++ b/src/uuid/mod.rs @@ -13,8 +13,8 @@ //! binary values. Instead, when serialized with `bson::to_bson`, it produces as a string, and when //! serialized with `bson::to_vec`, it produces a binary value with subtype _0_ rather than 4. //! Because of this, it is highly recommended to use the [`crate::Uuid`] type when working with BSON -//! instead of the `uuid` crate's `Uuid`, since [`crate::Uuid`] correctly produces subtype 4 binary -//! values via either serialization function. +//! instead of the `uuid` crate's [`Uuid`], since [`crate::Uuid`] correctly produces subtype 4 +//! binary values via either serialization function. //! //! e.g. //! @@ -44,10 +44,10 @@ //! //! ## The `uuid-1` feature flag //! -//! To facilitate the conversion between [`crate::Uuid`] values and the `uuid` crate's `Uuid` +//! To facilitate the conversion between [`crate::Uuid`] values and the `uuid` crate's [`Uuid`] //! values, the `uuid-1` feature flag can be enabled. This flag exposes a number of convenient //! conversions, including the `crate::Uuid::to_uuid_1` method and the `From` -//! implementation for `Bson`, which allows the `uuid` crate's `Uuid` values to be used in the +//! implementation for [`Bson`], which allows the `uuid` crate's [`Uuid`] values to be used in the //! `doc!` and `bson!` macros. //! //! ``` @@ -77,10 +77,10 @@ //! ## The `serde_with` feature flag //! //! The `serde_with` feature can be enabled to support more ergonomic serde attributes for -//! (de)serializing `uuid::Uuid` from/to BSON via the [`serde_with`](https://docs.rs/serde_with/1.11.0/serde_with/) +//! (de)serializing [`uuid::Uuid`] from/to BSON via the [`serde_with`](https://docs.rs/serde_with/1.11.0/serde_with/) //! crate. The main benefit of this compared to the regular `serde_helpers` is that `serde_with` can -//! handle nested `uuid::Uuid` values (e.g. in `Option`), whereas the former only works on fields -//! that are exactly `uuid::Uuid`. +//! handle nested [`uuid::Uuid`] values (e.g. in [`Option`]), whereas the former only works on +//! fields that are exactly [`uuid::Uuid`]. //! ``` //! # #[cfg(all(feature = "uuid-1", feature = "serde_with"))] //! # { @@ -91,7 +91,7 @@ //! #[serde_with::serde_as] //! #[derive(Deserialize, Serialize, PartialEq, Debug)] //! struct Foo { -//! /// Serializes as a BSON binary rather than using `uuid::Uuid`'s serialization +//! /// Serializes as a BSON binary rather than using [`uuid::Uuid`]'s serialization //! #[serde_as(as = "Option")] //! as_bson: Option, //! } @@ -109,9 +109,9 @@ //! # Ok::<(), Box>(()) //! ``` //! -//! ## Using `crate::Uuid` with non-BSON formats +//! ## Using [`crate::Uuid`] with non-BSON formats //! -//! [`crate::Uuid`]'s `serde` implementation is the same as `uuid::Uuid`'s +//! [`crate::Uuid`]'s `serde` implementation is the same as [`uuid::Uuid`]'s //! for non-BSON formats such as JSON: //! //! ``` rust @@ -147,9 +147,9 @@ use serde::{Deserialize, Serialize}; use crate::{de::BsonVisitor, spec::BinarySubtype, Binary, Bson}; -/// Special type name used in the `Uuid` serialization implementation to indicate a BSON +/// Special type name used in the [`Uuid`] serialization implementation to indicate a BSON /// UUID is being serialized or deserialized. The BSON serializers/deserializers will handle this -/// name specially, but other serializers/deserializers will just ignore it and use `uuid::Uuid`'s +/// name specially, but other serializers/deserializers will just ignore it and use [`uuid::Uuid`]'s /// serde integration. pub(crate) const UUID_NEWTYPE_NAME: &str = "$__bson_private_uuid"; @@ -160,7 +160,7 @@ pub(crate) const UUID_NEWTYPE_NAME: &str = "$__bson_private_uuid"; /// [`uuid::Uuid`](https://docs.rs/uuid/latest/uuid/struct.Uuid.html)'s `serde` implementation doesn't /// produce or parse BSON UUIDs. /// -/// To enable interop with the `Uuid` type from the `uuid` crate, enable the `uuid-0_8` feature +/// To enable interop with the [`Uuid`] type from the `uuid` crate, enable the `uuid-0_8` feature /// flag. /// /// For more information on the usage of this type, see the [`uuid`] module-level documentation.