Skip to content

Commit a8b5aa4

Browse files
fix docs tests
1 parent b82d03c commit a8b5aa4

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/binary/vector.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,26 @@ const PACKED_BIT: u8 = 0x10;
1616
/// [`BinarySubtype::Vector`].
1717
///
1818
/// ```rust
19+
/// # use bson::binary::{Binary, Vector};
1920
/// let vector = Vector::Int8(vec![0, 1, 2]);
2021
/// let binary = Binary::from(vector);
2122
/// ```
2223
///
23-
/// The `Serialize` and `Deserialize` implementations for `Vector` treat it as a `Binary`.
24+
/// `Vector` serializes to and deserializes from a `Binary`.
2425
///
2526
/// ```rust
27+
/// # use serde::{Serialize, Deserialize};
28+
/// # use bson::{binary::{Result, Vector}, spec::ElementType};
2629
/// #[derive(Serialize, Deserialize)]
2730
/// struct Data {
2831
/// vector: Vector,
2932
/// }
3033
///
3134
/// let data = Data { vector: Vector::Int8(vec![0, 1, 2]) };
32-
/// let document = bson::to_document(&data);
35+
/// let document = bson::to_document(&data).unwrap();
3336
/// assert_eq!(document.get("vector").unwrap().element_type(), ElementType::Binary);
3437
///
35-
/// let data = bson::from_document(document);
38+
/// let data: Data = bson::from_document(document).unwrap();
3639
/// assert_eq!(data.vector, Vector::Int8(vec![0, 1, 2]));
3740
/// ```
3841
///
@@ -63,21 +66,25 @@ impl PackedBitVector {
6366
/// single-bit elements in little-endian format. For example, the following vector:
6467
///
6568
/// ```rust
69+
/// # use bson::binary::{Result, PackedBitVector};
70+
/// # fn main() -> Result<()> {
6671
/// let packed_bits = vec![238, 224];
67-
/// let vector = PackedBitVector::new(packed_bits, 0);
72+
/// let vector = PackedBitVector::new(packed_bits, 0)?;
73+
/// # Ok(())
74+
/// # }
6875
/// ```
6976
///
7077
/// represents a 16-bit vector containing the following values:
7178
///
72-
/// ```
79+
/// ```text
7380
/// [1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0]
7481
/// ```
7582
///
7683
/// Padding can optionally be specified to ignore a number of least-significant bits in the
7784
/// final byte. For example, the vector in the previous example with a padding of 4 would
7885
/// represent a 12-bit vector containing the following values:
7986
///
80-
/// ```
87+
/// ```text
8188
/// [1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0]
8289
/// ```
8390
///

0 commit comments

Comments
 (0)