@@ -37,13 +37,19 @@ Download and Install
37
37
38
38
.. step:: Install the Rust Driver
39
39
40
- Add the following crates to your project by including them in the
40
+ Add the following crates to your project by including them in the
41
41
dependencies list located in your project's ``Cargo.toml`` file:
42
42
43
43
- ``mongodb``, the {+driver-short+} crate
44
- - ``bson``, the MongoDB data representation crate
45
- - ``serde_json``, A JSON data representation crate
46
-
44
+ - ``serde_json``, a JSON data representation crate
45
+ - ``futures``, an asynchronous runtime crate that provides core abstractions
46
+
47
+ .. tip::
48
+
49
+ The ``mongodb`` crate resolves the ``bson`` crate, which is the primary
50
+ MongoDB data representation crate. You do not need to add the ``bson``
51
+ crate to your dependencies list.
52
+
47
53
The following code shows an example dependencies list that
48
54
includes the preceding crates:
49
55
@@ -55,27 +61,60 @@ Download and Install
55
61
.. code-block:: bash
56
62
57
63
[dependencies]
58
- bson = "2.7.0"
59
64
serde_json = "1.0.107"
65
+ futures = "0.3.28"
66
+ tokio = {version = "1.32.0", features = ["full"]}
60
67
61
68
[dependencies.mongodb]
62
69
version = "{+version+}"
63
- default-features = false
64
- features = ["async-std-runtime"]
70
+ features = ["tokio-runtime"]
65
71
66
72
.. tab:: Synchronous API
67
73
:tabid: synchronous-api
68
74
69
75
.. code-block:: bash
70
76
71
77
[dependencies]
72
- bson = "2.7.0"
73
78
serde_json = "1.0.107"
74
79
75
80
[dependencies.mongodb]
76
81
version = "{+version+}"
77
82
features = ["tokio-sync"]
78
83
84
+ .. tip::
85
+
86
+ The ``tokio`` asynchronous runtime is the driver's default runtime crate
87
+ and does not require a feature flag. The preceding code example includes
88
+ the ``"tokio-runtime"`` feature flag to specify the ``tokio`` runtime, but
89
+ this flag is optional.
90
+
91
+ If you want to use a different synchronous or asynchronous runtime crate,
92
+ replace the feature flag with your runtime crate's corresponding flag.
93
+ The driver supports the following alternative feature flags, which use the
94
+ `async-std <https://crates.io/crates/async-std>`__ crate runtime:
95
+
96
+ - The ``"async-std-runtime"`` feature flag
97
+ - The ``"sync"`` feature flag
98
+
99
+ For more information about these feature flags, see the `API documentation
100
+ <{+api+}/#all-feature-flags>`__.
101
+
102
+ If you want to use both the asynchronous and synchronous runtimes, specify
103
+ the ``tokio`` runtime dependency and include the ``"tokio-sync"`` flag in
104
+ ``dependencies.mongodb``. The following code shows an example dependencies
105
+ list that supports sync and async code:
106
+
107
+ .. code-block:: bash
108
+
109
+ [dependencies]
110
+ serde_json = "1.0.107"
111
+ futures = "0.3.28"
112
+ tokio = {version = "1.32.0", features = ["full"]}
113
+
114
+ [dependencies.mongodb]
115
+ version = "2.6.1"
116
+ features = ["tokio-sync"]
117
+
79
118
After you complete these steps, you should have Rust and Cargo installed
80
119
and a new Rust project with the necessary driver dependencies.
81
120
0 commit comments