Struct cargo_edit::PathSource
source · 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: PathBufLocal, absolute path
version: Option<String>Version requirement for when published
Implementations§
source§impl PathSource
impl PathSource
sourcepub fn new(path: impl Into<PathBuf>) -> Self
pub fn new(path: impl Into<PathBuf>) -> Self
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}");
}
}sourcepub fn set_version(self, version: impl AsRef<str>) -> Self
pub fn set_version(self, version: impl AsRef<str>) -> Self
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§
source§impl Clone for PathSource
impl Clone for PathSource
source§fn clone(&self) -> PathSource
fn clone(&self) -> PathSource
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl Debug for PathSource
impl Debug for PathSource
source§impl Display for PathSource
impl Display for PathSource
source§impl From<PathSource> for Source
impl From<PathSource> for Source
source§fn from(inner: PathSource) -> Self
fn from(inner: PathSource) -> Self
Converts to this type from the input type.
source§impl Hash for PathSource
impl Hash for PathSource
source§impl Ord for PathSource
impl Ord for PathSource
source§fn cmp(&self, other: &PathSource) -> Ordering
fn cmp(&self, other: &PathSource) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl PartialEq<PathSource> for PathSource
impl PartialEq<PathSource> for PathSource
source§fn eq(&self, other: &PathSource) -> bool
fn eq(&self, other: &PathSource) -> bool
This method tests for
self and other values to be equal, and is used
by ==.source§impl PartialOrd<PathSource> for PathSource
impl PartialOrd<PathSource> for PathSource
source§fn partial_cmp(&self, other: &PathSource) -> Option<Ordering>
fn partial_cmp(&self, other: &PathSource) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self and other) and is used by the <=
operator. Read moreimpl Eq for PathSource
impl StructuralEq for PathSource
impl StructuralPartialEq for PathSource
Auto Trait Implementations§
impl RefUnwindSafe for PathSource
impl Send for PathSource
impl Sync for PathSource
impl Unpin for PathSource
impl UnwindSafe for PathSource
Blanket Implementations§
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.