@@ -137,44 +137,26 @@ To depend on a library hosted on [crates.io], you modify `hello_world.rs`:
137
137
138
138
// ! ```cargo
139
139
// ! [dependencies]
140
- // ! time = "0.1.12 "
140
+ // ! regex = "1.8.0 "
141
141
// ! ```
142
142
143
143
fn main () {
144
- println! (" Hello, world!" );
144
+ let re = Regex :: new (r " ^\d{4}-\d{2}-\d{2}$" ). unwrap ();
145
+ println! (" Did our date match? {}" , re . is_match (" 2014-01-01" ));
145
146
}
146
147
```
147
148
148
149
The ` cargo ` section is called a [ *** manifest*** ] [ def-manifest ] , and it contains all of the
149
150
metadata that Cargo needs to compile your package. This is written in the
150
151
[ TOML] format (pronounced /tɑməl/).
151
152
152
- ` time = "0.1.12 "` is the name of the [ crate] [ def-crate ] and a [ SemVer] version
153
+ ` regex = "1.8.0 "` is the name of the [ crate] [ def-crate ] and a [ SemVer] version
153
154
requirement. The [ specifying
154
155
dependencies] ( https://doc.rust-lang.org/cargo/guide/../reference/specifying-dependencies.html ) docs have more
155
156
information about the options you have here.
156
157
157
- If we also wanted to add a dependency on the ` regex ` crate, we would not need
158
- to add ` [dependencies] ` for each crate listed. Here's what your whole
159
- ` hello_world.rs ` file would look like with dependencies on the ` time ` and ` regex `
160
- crates:
161
-
162
- ``` rust
163
- #! / usr / bin / env cargo
164
-
165
- // ! ```cargo
166
- // ! [dependencies]
167
- // ! time = "0.1.12"
168
- // ! regex = "0.1.41"
169
- // ! ```
170
-
171
- fn main () {
172
- let re = Regex :: new (r " ^\d{4}-\d{2}-\d{2}$" ). unwrap ();
173
- println! (" Did our date match? {}" , re . is_match (" 2014-01-01" ));
174
- }
175
- ```
176
-
177
- You can then re-run this and Cargo will fetch the new dependencies and all of their dependencies. You can see this by passing in ` --verbose ` :
158
+ You can then re-run this and Cargo will fetch the new dependencies and all of
159
+ their dependencies. You can see this by passing in ` --verbose ` :
178
160
``` console
179
161
$ cargo --verbose ./hello_world.rs
180
162
Updating crates.io index
@@ -194,6 +176,11 @@ $ cargo --verbose ./hello_world.rs
194
176
Did our date match? true
195
177
```
196
178
179
+ Cargo will cache the exact information about which revision of all of these dependencies we used.
180
+
181
+ Now, if ` regex ` gets updated, we will still build with the same revision until
182
+ we choose to ` cargo update --manifest-path hello_world.rs ` .
183
+
197
184
## Package Layout
198
185
199
186
* (Adapted from [ the cargo book] ( https://doc.rust-lang.org/cargo/guide/project-layout.html ) )*
0 commit comments