[go: up one dir, main page]

Struct cargo_edit::PathSource

source ·
#[non_exhaustive]
pub struct PathSource { pub path: PathBuf, pub version: Option<String>, }
Expand description

Dependency from a local path

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§path: PathBuf

Local, absolute path

§version: Option<String>

Version requirement for when published

Implementations§

Specify dependency from a path

Examples found in repository?
src/dependency.rs (line 205)
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
    pub fn from_toml(crate_root: &Path, key: &str, item: &toml_edit::Item) -> CargoResult<Self> {
        if let Some(version) = item.as_str() {
            let dep = Self::new(key).set_source(RegistrySource::new(version));
            Ok(dep)
        } else if let Some(table) = item.as_table_like() {
            let (name, rename) = if let Some(value) = table.get("package") {
                (
                    value
                        .as_str()
                        .ok_or_else(|| invalid_type(key, "package", value.type_name(), "string"))?
                        .to_owned(),
                    Some(key.to_owned()),
                )
            } else {
                (key.to_owned(), None)
            };

            let source: Source =
                if let Some(git) = table.get("git") {
                    let mut src = GitSource::new(
                        git.as_str()
                            .ok_or_else(|| invalid_type(key, "git", git.type_name(), "string"))?,
                    );
                    if let Some(value) = table.get("branch") {
                        src = src.set_branch(value.as_str().ok_or_else(|| {
                            invalid_type(key, "branch", value.type_name(), "string")
                        })?);
                    }
                    if let Some(value) = table.get("tag") {
                        src = src.set_tag(value.as_str().ok_or_else(|| {
                            invalid_type(key, "tag", value.type_name(), "string")
                        })?);
                    }
                    if let Some(value) = table.get("rev") {
                        src = src.set_rev(value.as_str().ok_or_else(|| {
                            invalid_type(key, "rev", value.type_name(), "string")
                        })?);
                    }
                    if let Some(value) = table.get("version") {
                        src = src.set_version(value.as_str().ok_or_else(|| {
                            invalid_type(key, "version", value.type_name(), "string")
                        })?);
                    }
                    src.into()
                } else if let Some(path) = table.get("path") {
                    let path = crate_root
                        .join(path.as_str().ok_or_else(|| {
                            invalid_type(key, "path", path.type_name(), "string")
                        })?);
                    let mut src = PathSource::new(path);
                    if let Some(value) = table.get("version") {
                        src = src.set_version(value.as_str().ok_or_else(|| {
                            invalid_type(key, "version", value.type_name(), "string")
                        })?);
                    }
                    src.into()
                } else if let Some(version) = table.get("version") {
                    let src = RegistrySource::new(version.as_str().ok_or_else(|| {
                        invalid_type(key, "version", version.type_name(), "string")
                    })?);
                    src.into()
                } else if let Some(workspace) = table.get("workspace") {
                    let workspace_bool = workspace.as_bool().ok_or_else(|| {
                        invalid_type(key, "workspace", workspace.type_name(), "bool")
                    })?;
                    if !workspace_bool {
                        anyhow::bail!("`{key}.workspace = false` is unsupported")
                    }
                    let src = WorkspaceSource::new();
                    src.into()
                } else {
                    anyhow::bail!("Unrecognized dependency source for `{key}`");
                };
            let registry = if let Some(value) = table.get("registry") {
                Some(
                    value
                        .as_str()
                        .ok_or_else(|| invalid_type(key, "registry", value.type_name(), "string"))?
                        .to_owned(),
                )
            } else {
                None
            };

            let default_features = table.get("default-features").and_then(|v| v.as_bool());
            if table.contains_key("default_features") {
                anyhow::bail!("Use of `default_features` in `{key}` is unsupported, please switch to `default-features`");
            }

            let features = if let Some(value) = table.get("features") {
                Some(
                    value
                        .as_array()
                        .ok_or_else(|| invalid_type(key, "features", value.type_name(), "array"))?
                        .iter()
                        .map(|v| {
                            v.as_str().map(|s| s.to_owned()).ok_or_else(|| {
                                invalid_type(key, "features", v.type_name(), "string")
                            })
                        })
                        .collect::<CargoResult<Vec<String>>>()?,
                )
            } else {
                None
            };

            let available_features = BTreeMap::default();

            let optional = table.get("optional").and_then(|v| v.as_bool());

            let dep = Self {
                name,
                rename,
                source: Some(source),
                registry,
                default_features,
                features,
                available_features,
                optional,
                inherited_features: None,
            };
            Ok(dep)
        } else {
            anyhow::bail!("Unrecognized` dependency entry format for `{key}");
        }
    }

Set an optional version requirement

Examples found in repository?
src/dependency.rs (lines 207-209)
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
    pub fn from_toml(crate_root: &Path, key: &str, item: &toml_edit::Item) -> CargoResult<Self> {
        if let Some(version) = item.as_str() {
            let dep = Self::new(key).set_source(RegistrySource::new(version));
            Ok(dep)
        } else if let Some(table) = item.as_table_like() {
            let (name, rename) = if let Some(value) = table.get("package") {
                (
                    value
                        .as_str()
                        .ok_or_else(|| invalid_type(key, "package", value.type_name(), "string"))?
                        .to_owned(),
                    Some(key.to_owned()),
                )
            } else {
                (key.to_owned(), None)
            };

            let source: Source =
                if let Some(git) = table.get("git") {
                    let mut src = GitSource::new(
                        git.as_str()
                            .ok_or_else(|| invalid_type(key, "git", git.type_name(), "string"))?,
                    );
                    if let Some(value) = table.get("branch") {
                        src = src.set_branch(value.as_str().ok_or_else(|| {
                            invalid_type(key, "branch", value.type_name(), "string")
                        })?);
                    }
                    if let Some(value) = table.get("tag") {
                        src = src.set_tag(value.as_str().ok_or_else(|| {
                            invalid_type(key, "tag", value.type_name(), "string")
                        })?);
                    }
                    if let Some(value) = table.get("rev") {
                        src = src.set_rev(value.as_str().ok_or_else(|| {
                            invalid_type(key, "rev", value.type_name(), "string")
                        })?);
                    }
                    if let Some(value) = table.get("version") {
                        src = src.set_version(value.as_str().ok_or_else(|| {
                            invalid_type(key, "version", value.type_name(), "string")
                        })?);
                    }
                    src.into()
                } else if let Some(path) = table.get("path") {
                    let path = crate_root
                        .join(path.as_str().ok_or_else(|| {
                            invalid_type(key, "path", path.type_name(), "string")
                        })?);
                    let mut src = PathSource::new(path);
                    if let Some(value) = table.get("version") {
                        src = src.set_version(value.as_str().ok_or_else(|| {
                            invalid_type(key, "version", value.type_name(), "string")
                        })?);
                    }
                    src.into()
                } else if let Some(version) = table.get("version") {
                    let src = RegistrySource::new(version.as_str().ok_or_else(|| {
                        invalid_type(key, "version", version.type_name(), "string")
                    })?);
                    src.into()
                } else if let Some(workspace) = table.get("workspace") {
                    let workspace_bool = workspace.as_bool().ok_or_else(|| {
                        invalid_type(key, "workspace", workspace.type_name(), "bool")
                    })?;
                    if !workspace_bool {
                        anyhow::bail!("`{key}.workspace = false` is unsupported")
                    }
                    let src = WorkspaceSource::new();
                    src.into()
                } else {
                    anyhow::bail!("Unrecognized dependency source for `{key}`");
                };
            let registry = if let Some(value) = table.get("registry") {
                Some(
                    value
                        .as_str()
                        .ok_or_else(|| invalid_type(key, "registry", value.type_name(), "string"))?
                        .to_owned(),
                )
            } else {
                None
            };

            let default_features = table.get("default-features").and_then(|v| v.as_bool());
            if table.contains_key("default_features") {
                anyhow::bail!("Use of `default_features` in `{key}` is unsupported, please switch to `default-features`");
            }

            let features = if let Some(value) = table.get("features") {
                Some(
                    value
                        .as_array()
                        .ok_or_else(|| invalid_type(key, "features", value.type_name(), "array"))?
                        .iter()
                        .map(|v| {
                            v.as_str().map(|s| s.to_owned()).ok_or_else(|| {
                                invalid_type(key, "features", v.type_name(), "string")
                            })
                        })
                        .collect::<CargoResult<Vec<String>>>()?,
                )
            } else {
                None
            };

            let available_features = BTreeMap::default();

            let optional = table.get("optional").and_then(|v| v.as_bool());

            let dep = Self {
                name,
                rename,
                source: Some(source),
                registry,
                default_features,
                features,
                available_features,
                optional,
                inherited_features: None,
            };
            Ok(dep)
        } else {
            anyhow::bail!("Unrecognized` dependency entry format for `{key}");
        }
    }

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Compare self to key and return true if they are equal.

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.