Skip to content

RUST-782 Add hyperlinks for all types in rustdoc #389

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand Down
49 changes: 28 additions & 21 deletions src/bson.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -841,152 +841,159 @@ 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<f64> {
match *self {
Bson::Double(v) => Some(v),
_ => None,
}
}

/// 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),
_ => None,
}
}

/// 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),
_ => None,
}
}

/// 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),
_ => None,
}
}

/// 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),
_ => None,
}
}

/// 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),
_ => None,
}
}

/// 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),
_ => None,
}
}

/// 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<bool> {
match *self {
Bson::Boolean(v) => Some(v),
_ => None,
}
}

/// 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<i32> {
match *self {
Bson::Int32(v) => Some(v),
_ => None,
}
}

/// 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<i64> {
match *self {
Bson::Int64(v) => Some(v),
_ => None,
}
}

/// 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<oid::ObjectId> {
match *self {
Bson::ObjectId(v) => Some(v),
_ => None,
}
}

/// 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),
_ => None,
}
}

/// 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),
_ => None,
}
}

/// 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),
_ => None,
}
}

/// 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),
_ => None,
}
}

/// 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),
_ => None,
}
}

/// 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<Timestamp> {
match *self {
Bson::Timestamp(timestamp) => Some(timestamp),
_ => None,
}
}

/// 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(()),
_ => None,
}
}

/// 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),
Expand Down
18 changes: 9 additions & 9 deletions src/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
/// # {
Expand All @@ -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<bson::DateTime>")]
/// as_bson: Option<chrono::DateTime<chrono::Utc>>,
/// }
Expand Down Expand Up @@ -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<T: chrono::TimeZone>(dt: chrono::DateTime<T>) -> Self {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 },
}
Expand Down
7 changes: 4 additions & 3 deletions src/de/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -91,7 +91,8 @@ impl de::Error for Error {
pub type Result<T> = std::result::Result<T, Error>;

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,
Expand Down
8 changes: 4 additions & 4 deletions src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading