Skip to content

Commit

Permalink
Fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake-Shadle committed Jun 26, 2024
1 parent cbe66a0 commit f0c4c57
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 45 deletions.
22 changes: 5 additions & 17 deletions src/cm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ pub enum TargetKind {
Test,
}

#[allow(clippy::fallible_impl_from)]
impl From<&str> for TargetKind {
fn from(value: &str) -> Self {
match value {
Expand Down Expand Up @@ -555,6 +556,7 @@ pub enum CrateType {
StaticLib,
}

#[allow(clippy::fallible_impl_from)]
impl From<&str> for CrateType {
fn from(value: &str) -> Self {
match value {
Expand All @@ -574,7 +576,6 @@ impl From<&str> for CrateType {
///
/// As of writing this comment rust editions 2024, 2027 and 2030 are not actually a thing yet but are parsed nonetheless for future proofing.
#[derive(Debug, Clone, Copy, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[non_exhaustive]
pub enum Edition {
/// Edition 2015
#[serde(rename = "2015")]
Expand All @@ -585,28 +586,15 @@ pub enum Edition {
/// Edition 2021
#[serde(rename = "2021")]
E2021,
#[doc(hidden)]
#[serde(rename = "2024")]
_E2024,
#[doc(hidden)]
#[serde(rename = "2027")]
_E2027,
#[doc(hidden)]
#[serde(rename = "2030")]
_E2030,
}

impl Edition {
/// Return the string representation of the edition
pub fn as_str(&self) -> &'static str {
use Edition::*;
match self {
E2015 => "2015",
E2018 => "2018",
E2021 => "2021",
_E2024 => "2024",
_E2027 => "2027",
_E2030 => "2030",
Self::E2015 => "2015",
Self::E2018 => "2018",
Self::E2021 => "2021",
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/cm/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use std::{ffi::OsString, process::Command};

/// Cargo features flags
#[derive(Debug, Clone)]
pub enum CargoOpt {
pub enum Features {
/// Run cargo with `--features-all`
AllFeatures,
All,
/// Run cargo with `--no-default-features`
NoDefaultFeatures,
NoDefault,
/// Run cargo with `--features <FEATURES>`
SomeFeatures(Vec<String>),
Selected(Vec<String>),
}

/// A builder for configurating `cargo metadata` invocation.
Expand Down Expand Up @@ -71,17 +71,17 @@ impl MetadataCommand {
self
}
/// Which features to include.
pub fn features(&mut self, features: CargoOpt) -> &mut Self {
pub fn features(&mut self, features: Features) -> &mut Self {
match features {
CargoOpt::SomeFeatures(features) => self.features.extend(features),
CargoOpt::NoDefaultFeatures => {
Features::Selected(features) => self.features.extend(features),
Features::NoDefault => {
assert!(
!self.no_default_features,
"Do not supply CargoOpt::NoDefaultFeatures more than once!"
);
self.no_default_features = true;
}
CargoOpt::AllFeatures => {
Features::All => {
assert!(
!self.all_features,
"Do not supply CargoOpt::AllFeatures more than once!"
Expand Down Expand Up @@ -156,8 +156,8 @@ impl MetadataCommand {

/// Parses `cargo metadata` output. `data` must have been
/// produced by a command built with `cargo_command`.
pub fn parse<T: AsRef<str>>(data: T) -> Result<super::Metadata, Error> {
let meta = serde_json::from_str(data.as_ref())?;
pub fn parse(data: &str) -> Result<super::Metadata, Error> {
let meta = serde_json::from_str(data)?;
Ok(meta)
}

Expand Down
17 changes: 0 additions & 17 deletions src/cm/errors.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
use std::{fmt, io, str::Utf8Error, string::FromUtf8Error};

/// Error returned when executing/parsing `cargo metadata` fails.
///
/// # Note about Backtraces
///
/// This error type does not contain backtraces, but each error variant
/// comes from _one_ specific place, so it's not really needed for the
/// inside of this crate. If you need a backtrace down to, but not inside
/// of, a failed call of `cargo_metadata` you can do one of multiple thinks:
///
/// 1. Convert it to a `failure::Error` (possible using the `?` operator),
/// which is similar to a `Box<::std::error::Error + 'static + Send + Sync>`.
/// 2. Have appropriate variants in your own error type. E.g. you could wrap
/// a `failure::Context<Error>` or add a `failure::Backtrace` field (which
/// is empty if `RUST_BACKTRACE` is not set, so it's simple to use).
/// 3. You still can place a failure based error into a `error_chain` if you
/// really want to. (Either through foreign_links or by making it a field
/// value of a `ErrorKind` variant).
///
#[derive(Debug)]
pub enum Error {
/// Error during execution of `cargo metadata`
Expand Down
5 changes: 4 additions & 1 deletion tests/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ pub fn build<P: AsRef<Path>>(src: P, kb: krates::Builder) -> Result<Grafs, Strin
id.clone().into(),
krates::Edge::Dep {
kind: dk.kind.into(),
cfg: dk.target.map(|f| f.to_string()),
#[cfg(not(feature = "metadata"))]
cfg: dk.target.clone(),
#[cfg(feature = "metadata")]
cfg: dk.target.map(|s| s.to_string()),
},
)
})
Expand Down

0 comments on commit f0c4c57

Please sign in to comment.