Skip to content

Commit 739b84b

Browse files
authored
RUST-782 Add hyperlinks for all types in rustdoc (#389)
1 parent 56dc006 commit 739b84b

24 files changed

+168
-160
lines changed

src/binary.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl Display for Binary {
2828

2929
impl Binary {
3030
/// Creates a [`Binary`] from a base64 string and optional [`BinarySubtype`]. If the
31-
/// `subtype` argument is `None`, the [`Binary`] constructed will default to
31+
/// `subtype` argument is [`None`], the [`Binary`] constructed will default to
3232
/// [`BinarySubtype::Generic`].
3333
///
3434
/// ```rust
@@ -83,7 +83,7 @@ impl Binary {
8383
}
8484
}
8585

86-
/// Borrow the contents as a `RawBinaryRef`.
86+
/// Borrow the contents as a [`RawBinaryRef`].
8787
pub fn as_raw_binary(&self) -> RawBinaryRef<'_> {
8888
RawBinaryRef {
8989
bytes: self.bytes.as_slice(),

src/bson.rs

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ impl Bson {
514514
}
515515
}
516516

517-
/// Get the `ElementType` of this value.
517+
/// Get the [`ElementType`] of this value.
518518
pub fn element_type(&self) -> ElementType {
519519
match *self {
520520
Bson::Double(..) => ElementType::Double,
@@ -841,152 +841,159 @@ impl Bson {
841841

842842
/// Value helpers
843843
impl Bson {
844-
/// If `Bson` is `Double`, return its value as an `f64`. Returns `None` otherwise
844+
/// If `self` is [`Double`](Bson::Double), return its value as an `f64`. Returns [`None`]
845+
/// otherwise.
845846
pub fn as_f64(&self) -> Option<f64> {
846847
match *self {
847848
Bson::Double(v) => Some(v),
848849
_ => None,
849850
}
850851
}
851852

852-
/// If `Bson` is `String`, return its value as a `&str`. Returns `None` otherwise
853+
/// If `self` is [`String`](Bson::String), return its value as a `&str`. Returns [`None`]
854+
/// otherwise.
853855
pub fn as_str(&self) -> Option<&str> {
854856
match *self {
855857
Bson::String(ref s) => Some(s),
856858
_ => None,
857859
}
858860
}
859861

860-
/// If `Bson` is `String`, return a mutable reference to its value as a `str`. Returns `None`
861-
/// otherwise
862+
/// If `self` is [`String`](Bson::String), return a mutable reference to its value as a [`str`].
863+
/// Returns [`None`] otherwise.
862864
pub fn as_str_mut(&mut self) -> Option<&mut str> {
863865
match *self {
864866
Bson::String(ref mut s) => Some(s),
865867
_ => None,
866868
}
867869
}
868870

869-
/// If `Bson` is `Array`, return its value. Returns `None` otherwise
871+
/// If `self` is [`Array`](Bson::Array), return its value. Returns [`None`] otherwise.
870872
pub fn as_array(&self) -> Option<&Array> {
871873
match *self {
872874
Bson::Array(ref v) => Some(v),
873875
_ => None,
874876
}
875877
}
876878

877-
/// If `Bson` is `Array`, return a mutable reference to its value. Returns `None` otherwise
879+
/// If `self` is [`Array`](Bson::Array), return a mutable reference to its value. Returns
880+
/// [`None`] otherwise.
878881
pub fn as_array_mut(&mut self) -> Option<&mut Array> {
879882
match *self {
880883
Bson::Array(ref mut v) => Some(v),
881884
_ => None,
882885
}
883886
}
884887

885-
/// If `Bson` is `Document`, return its value. Returns `None` otherwise
888+
/// If `self` is [`Document`](Bson::Document), return its value. Returns [`None`] otherwise.
886889
pub fn as_document(&self) -> Option<&Document> {
887890
match *self {
888891
Bson::Document(ref v) => Some(v),
889892
_ => None,
890893
}
891894
}
892895

893-
/// If `Bson` is `Document`, return a mutable reference to its value. Returns `None` otherwise
896+
/// If `self` is [`Document`](Bson::Document), return a mutable reference to its value. Returns
897+
/// [`None`] otherwise.
894898
pub fn as_document_mut(&mut self) -> Option<&mut Document> {
895899
match *self {
896900
Bson::Document(ref mut v) => Some(v),
897901
_ => None,
898902
}
899903
}
900904

901-
/// If `Bson` is `Bool`, return its value. Returns `None` otherwise
905+
/// If `self` is [`Boolean`](Bson::Boolean), return its value. Returns [`None`] otherwise.
902906
pub fn as_bool(&self) -> Option<bool> {
903907
match *self {
904908
Bson::Boolean(v) => Some(v),
905909
_ => None,
906910
}
907911
}
908912

909-
/// If `Bson` is `I32`, return its value. Returns `None` otherwise
913+
/// If `self` is [`Int32`](Bson::Int32), return its value. Returns [`None`] otherwise.
910914
pub fn as_i32(&self) -> Option<i32> {
911915
match *self {
912916
Bson::Int32(v) => Some(v),
913917
_ => None,
914918
}
915919
}
916920

917-
/// If `Bson` is `I64`, return its value. Returns `None` otherwise
921+
/// If `self` is [`Int64`](Bson::Int64), return its value. Returns [`None`] otherwise.
918922
pub fn as_i64(&self) -> Option<i64> {
919923
match *self {
920924
Bson::Int64(v) => Some(v),
921925
_ => None,
922926
}
923927
}
924928

925-
/// If `Bson` is `Objectid`, return its value. Returns `None` otherwise
929+
/// If `self` is [`ObjectId`](Bson::ObjectId), return its value. Returns [`None`] otherwise.
926930
pub fn as_object_id(&self) -> Option<oid::ObjectId> {
927931
match *self {
928932
Bson::ObjectId(v) => Some(v),
929933
_ => None,
930934
}
931935
}
932936

933-
/// If `Bson` is `Objectid`, return a mutable reference to its value. Returns `None` otherwise
937+
/// If `self` is [`ObjectId`](Bson::ObjectId), return a mutable reference to its value. Returns
938+
/// [`None`] otherwise.
934939
pub fn as_object_id_mut(&mut self) -> Option<&mut oid::ObjectId> {
935940
match *self {
936941
Bson::ObjectId(ref mut v) => Some(v),
937942
_ => None,
938943
}
939944
}
940945

941-
/// If `Bson` is `DateTime`, return its value. Returns `None` otherwise
946+
/// If `self` is [`DateTime`](Bson::DateTime), return its value. Returns [`None`] otherwise.
942947
pub fn as_datetime(&self) -> Option<&crate::DateTime> {
943948
match *self {
944949
Bson::DateTime(ref v) => Some(v),
945950
_ => None,
946951
}
947952
}
948953

949-
/// If `Bson` is `DateTime`, return a mutable reference to its value. Returns `None`
950-
/// otherwise
954+
/// If `self` is [`DateTime`](Bson::DateTime), return a mutable reference to its value. Returns
955+
/// [`None`] otherwise.
951956
pub fn as_datetime_mut(&mut self) -> Option<&mut crate::DateTime> {
952957
match *self {
953958
Bson::DateTime(ref mut v) => Some(v),
954959
_ => None,
955960
}
956961
}
957962

958-
/// If `Bson` is `Symbol`, return its value. Returns `None` otherwise
963+
/// If `self` is [`Symbol`](Bson::Symbol), return its value. Returns [`None`] otherwise.
959964
pub fn as_symbol(&self) -> Option<&str> {
960965
match *self {
961966
Bson::Symbol(ref v) => Some(v),
962967
_ => None,
963968
}
964969
}
965970

966-
/// If `Bson` is `Symbol`, return a mutable reference to its value. Returns `None` otherwise
971+
/// If `self` is [`Symbol`](Bson::Symbol), return a mutable reference to its value. Returns
972+
/// [`None`] otherwise.
967973
pub fn as_symbol_mut(&mut self) -> Option<&mut str> {
968974
match *self {
969975
Bson::Symbol(ref mut v) => Some(v),
970976
_ => None,
971977
}
972978
}
973979

974-
/// If `Bson` is `Timestamp`, return its value. Returns `None` otherwise
980+
/// If `self` is [`Timestamp`](Bson::Timestamp), return its value. Returns [`None`] otherwise.
975981
pub fn as_timestamp(&self) -> Option<Timestamp> {
976982
match *self {
977983
Bson::Timestamp(timestamp) => Some(timestamp),
978984
_ => None,
979985
}
980986
}
981987

982-
/// If `Bson` is `Null`, return its value. Returns `None` otherwise
988+
/// If `self` is [`Null`](Bson::Null), return `()`. Returns [`None`] otherwise.
983989
pub fn as_null(&self) -> Option<()> {
984990
match *self {
985991
Bson::Null => Some(()),
986992
_ => None,
987993
}
988994
}
989995

996+
/// If `self` is [`DbPointer`](Bson::DbPointer), return its value. Returns [`None`] otherwise.
990997
pub fn as_db_pointer(&self) -> Option<&DbPointer> {
991998
match self {
992999
Bson::DbPointer(ref db_pointer) => Some(db_pointer),

src/datetime.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ use serde_with::{DeserializeAs, SerializeAs};
8787
/// ## The `serde_with` feature flag
8888
///
8989
/// The `serde_with` feature can be enabled to support more ergonomic serde attributes for
90-
/// (de)serializing `chrono::DateTime` from/to BSON via the [`serde_with`](https://docs.rs/serde_with/1.11.0/serde_with/)
90+
/// (de)serializing [`chrono::DateTime`] from/to BSON via the [`serde_with`](https://docs.rs/serde_with/1.11.0/serde_with/)
9191
/// crate. The main benefit of this compared to the regular `serde_helpers` is that `serde_with` can
92-
/// handle nested `chrono::DateTime` values (e.g. in `Option`), whereas the former only works on
93-
/// fields that are exactly `chrono::DateTime`.
92+
/// handle nested [`chrono::DateTime`] values (e.g. in [`Option`]), whereas the former only works on
93+
/// fields that are exactly [`chrono::DateTime`].
9494
/// ```
9595
/// # #[cfg(all(feature = "chrono-0_4", feature = "serde_with"))]
9696
/// # {
@@ -100,7 +100,7 @@ use serde_with::{DeserializeAs, SerializeAs};
100100
/// #[serde_with::serde_as]
101101
/// #[derive(Deserialize, Serialize, PartialEq, Debug)]
102102
/// struct Foo {
103-
/// /// Serializes as a BSON datetime rather than using `chrono::DateTime`'s serialization
103+
/// /// Serializes as a BSON datetime rather than using [`chrono::DateTime`]'s serialization
104104
/// #[serde_as(as = "Option<bson::DateTime>")]
105105
/// as_bson: Option<chrono::DateTime<chrono::Utc>>,
106106
/// }
@@ -139,8 +139,8 @@ impl crate::DateTime {
139139
Self::from_system_time(SystemTime::now())
140140
}
141141

142-
/// Convert the given `chrono::DateTime` into a `bson::DateTime`, truncating it to millisecond
143-
/// precision.
142+
/// Convert the given [`chrono::DateTime`] into a [`bson::DateTime`](DateTime), truncating it to
143+
/// millisecond precision.
144144
#[cfg(feature = "chrono-0_4")]
145145
#[cfg_attr(docsrs, doc(cfg(feature = "chrono-0_4")))]
146146
pub fn from_chrono<T: chrono::TimeZone>(dt: chrono::DateTime<T>) -> Self {
@@ -206,8 +206,8 @@ impl crate::DateTime {
206206
Self::from_time_private(dt)
207207
}
208208

209-
/// Convert the given `time::OffsetDateTime` into a `bson::DateTime`, truncating it to
210-
/// millisecond precision.
209+
/// Convert the given [`time::OffsetDateTime`] into a [`bson::DateTime`](DateTime), truncating
210+
/// it to millisecond precision.
211211
///
212212
/// If the provided time is too far in the future or too far in the past to be represented
213213
/// by a BSON datetime, either [`DateTime::MAX`] or [`DateTime::MIN`] will be
@@ -455,7 +455,7 @@ pub enum Error {
455455
/// Error returned when an invalid datetime format is provided to a conversion method.
456456
#[non_exhaustive]
457457
InvalidTimestamp { message: String },
458-
/// Error returned when a `DateTime` cannot be represented in a particular format.
458+
/// Error returned when a [`DateTime`] cannot be represented in a particular format.
459459
#[non_exhaustive]
460460
CannotFormat { message: String },
461461
}

src/de/error.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ pub enum Error {
1515
/// while decoding a UTF-8 String from the input data.
1616
InvalidUtf8String(string::FromUtf8Error),
1717

18-
/// While decoding a `Document` from bytes, an unexpected or unsupported element type was
19-
/// encountered.
18+
/// While decoding a [`Document`](crate::Document) from bytes, an unexpected or unsupported
19+
/// element type was encountered.
2020
#[non_exhaustive]
2121
UnrecognizedDocumentElementType {
2222
/// The key at which an unexpected/unsupported element type was encountered.
@@ -91,7 +91,8 @@ impl de::Error for Error {
9191
pub type Result<T> = std::result::Result<T, Error>;
9292

9393
impl Bson {
94-
/// Method for converting a given `Bson` value to a `serde::de::Unexpected` for error reporting.
94+
/// Method for converting a given [`Bson`] value to a [`serde::de::Unexpected`] for error
95+
/// reporting.
9596
pub(crate) fn as_unexpected(&self) -> Unexpected {
9697
match self {
9798
Bson::Array(_) => Unexpected::Seq,

src/de/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ enum DeserializerHint {
6565
None,
6666

6767
/// The type being deserialized expects the BSON to contain a binary value with the provided
68-
/// subtype. This is currently used to deserialize `bson::Uuid` values.
68+
/// subtype. This is currently used to deserialize [`bson::Uuid`] values.
6969
BinarySubtype(BinarySubtype),
7070

7171
/// The type being deserialized is raw BSON, meaning no allocations should occur as part of
72-
/// deserializing and everything should be visited via borrowing or `Copy` if possible.
72+
/// deserializing and everything should be visited via borrowing or [`Copy`] if possible.
7373
RawBson,
7474
}
7575

@@ -433,7 +433,7 @@ impl JavaScriptCodeWithScope {
433433

434434
/// Deserialize a `T` from the provided [`Bson`] value.
435435
///
436-
/// The `Deserializer` used by this function presents itself as human readable, whereas the
436+
/// The [`Deserializer`] used by this function presents itself as human readable, whereas the
437437
/// one used in [`from_slice`] does not. This means that this function may deserialize differently
438438
/// than [`from_slice`] for types that change their deserialization logic depending on whether
439439
/// the format is human readable or not. To deserialize from [`Bson`] with a deserializer that
@@ -473,7 +473,7 @@ where
473473

474474
/// Deserialize a `T` from the provided [`Document`].
475475
///
476-
/// The `Deserializer` used by this function presents itself as human readable, whereas the
476+
/// The [`Deserializer`] used by this function presents itself as human readable, whereas the
477477
/// one used in [`from_slice`] does not. This means that this function may deserialize differently
478478
/// than [`from_slice`] for types that change their deserialization logic depending on whether
479479
/// the format is human readable or not. To deserialize from [`Document`] with a deserializer that

0 commit comments

Comments
 (0)