@@ -16,23 +16,26 @@ const PACKED_BIT: u8 = 0x10;
16
16
/// [`BinarySubtype::Vector`].
17
17
///
18
18
/// ```rust
19
+ /// # use bson::binary::{Binary, Vector};
19
20
/// let vector = Vector::Int8(vec![0, 1, 2]);
20
21
/// let binary = Binary::from(vector);
21
22
/// ```
22
23
///
23
- /// The `Serialize` and `Deserialize` implementations for `Vector` treat it as a `Binary`.
24
+ /// `Vector` serializes to and deserializes from a `Binary`.
24
25
///
25
26
/// ```rust
27
+ /// # use serde::{Serialize, Deserialize};
28
+ /// # use bson::{binary::{Result, Vector}, spec::ElementType};
26
29
/// #[derive(Serialize, Deserialize)]
27
30
/// struct Data {
28
31
/// vector: Vector,
29
32
/// }
30
33
///
31
34
/// 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() ;
33
36
/// assert_eq!(document.get("vector").unwrap().element_type(), ElementType::Binary);
34
37
///
35
- /// let data = bson::from_document(document);
38
+ /// let data: Data = bson::from_document(document).unwrap( );
36
39
/// assert_eq!(data.vector, Vector::Int8(vec![0, 1, 2]));
37
40
/// ```
38
41
///
@@ -63,21 +66,25 @@ impl PackedBitVector {
63
66
/// single-bit elements in little-endian format. For example, the following vector:
64
67
///
65
68
/// ```rust
69
+ /// # use bson::binary::{Result, PackedBitVector};
70
+ /// # fn main() -> Result<()> {
66
71
/// 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
+ /// # }
68
75
/// ```
69
76
///
70
77
/// represents a 16-bit vector containing the following values:
71
78
///
72
- /// ```
79
+ /// ```text
73
80
/// [1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0]
74
81
/// ```
75
82
///
76
83
/// Padding can optionally be specified to ignore a number of least-significant bits in the
77
84
/// final byte. For example, the vector in the previous example with a padding of 4 would
78
85
/// represent a 12-bit vector containing the following values:
79
86
///
80
- /// ```
87
+ /// ```text
81
88
/// [1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0]
82
89
/// ```
83
90
///
0 commit comments