Skip to content
This repository has been archived by the owner on Jun 5, 2020. It is now read-only.

Commit

Permalink
Migrate to 2018 edition
Browse files Browse the repository at this point in the history
  • Loading branch information
sfackler committed Jan 31, 2019
1 parent 27a9182 commit 625b33d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 38 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "cargo-tree"
version = "0.23.0"
authors = ["Steven Fackler <[email protected]>"]
edition = "2018"
license = "MIT/Apache-2.0"
description = "A Cargo subcommand that visualizes a crate's dependency graph in a tree-like format"
repository = "https://github.com/sfackler/cargo-tree"
Expand Down
28 changes: 16 additions & 12 deletions src/format/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use cargo::core::PackageId;
use cargo::core::manifest::ManifestMetadata;
use cargo::core::PackageId;
use std::error::Error;
use std::fmt;

use format::parse::{Parser, RawChunk};
use crate::format::parse::{Parser, RawChunk};

mod parse;

Expand All @@ -17,7 +17,7 @@ enum Chunk {
pub struct Pattern(Vec<Chunk>);

impl Pattern {
pub fn new(format: &str) -> Result<Pattern, Box<Error>> {
pub fn new(format: &str) -> Result<Pattern, Box<dyn Error>> {
let mut chunks = vec![];

for raw in Parser::new(format) {
Expand Down Expand Up @@ -57,17 +57,21 @@ pub struct Display<'a> {
}

impl<'a> fmt::Display for Display<'a> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
for chunk in &self.pattern.0 {
match *chunk {
Chunk::Raw(ref s) => try!(fmt.write_str(s)),
Chunk::Package => try!(write!(fmt, "{}", self.package)),
Chunk::License => if let Some(ref license) = self.metadata.license {
try!(write!(fmt, "{}", license))
},
Chunk::Repository => if let Some(ref repository) = self.metadata.repository {
try!(write!(fmt, "{}", repository))
},
Chunk::Raw(ref s) => fmt.write_str(s)?,
Chunk::Package => write!(fmt, "{}", self.package)?,
Chunk::License => {
if let Some(ref license) = self.metadata.license {
write!(fmt, "{}", license)?
}
}
Chunk::Repository => {
if let Some(ref repository) = self.metadata.repository {
write!(fmt, "{}", repository)?
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/format/parse.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::str;
use std::iter;
use std::str;

pub enum RawChunk<'a> {
Text(&'a str),
Expand Down
32 changes: 7 additions & 25 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
extern crate cargo;
extern crate env_logger;
#[macro_use]
extern crate failure;
extern crate petgraph;
extern crate structopt;

use cargo::core::dependency::Kind;
use cargo::core::manifest::ManifestMetadata;
use cargo::core::package::PackageSet;
Expand All @@ -15,6 +8,7 @@ use cargo::core::{Package, PackageId, Resolve, Workspace};
use cargo::ops;
use cargo::util::{self, important_paths, CargoResult, Cfg, Rustc};
use cargo::{CliResult, Config};
use failure::bail;
use petgraph::graph::NodeIndex;
use petgraph::visit::EdgeRef;
use petgraph::EdgeDirection;
Expand All @@ -25,7 +19,7 @@ use std::str::{self, FromStr};
use structopt::clap::AppSettings;
use structopt::StructOpt;

use format::Pattern;
use crate::format::Pattern;

mod format;

Expand Down Expand Up @@ -62,23 +56,15 @@ struct Args {
/// Set the target triple
target: Option<String>,
/// Directory for all generated artifacts
#[structopt(
long = "target-dir",
value_name = "DIRECTORY",
parse(from_os_str)
)]
#[structopt(long = "target-dir", value_name = "DIRECTORY", parse(from_os_str))]
target_dir: Option<PathBuf>,
#[structopt(long = "all-targets")]
/// Return dependencies for all targets. By default only the host target is matched.
all_targets: bool,
#[structopt(long = "no-dev-dependencies")]
/// Skip dev dependencies.
no_dev_dependencies: bool,
#[structopt(
long = "manifest-path",
value_name = "PATH",
parse(from_os_str)
)]
#[structopt(long = "manifest-path", value_name = "PATH", parse(from_os_str))]
/// Path to Cargo.toml
manifest_path: Option<PathBuf>,
#[structopt(long = "invert", short = "i")]
Expand All @@ -96,11 +82,7 @@ struct Args {
#[structopt(long = "duplicate", short = "d")]
/// Show only dependencies which come in multiple versions (implies -i)
duplicates: bool,
#[structopt(
long = "charset",
value_name = "CHARSET",
default_value = "utf8"
)]
#[structopt(long = "charset", value_name = "CHARSET", default_value = "utf8")]
/// Character set to use in output: utf8, ascii
charset: Charset,
#[structopt(
Expand Down Expand Up @@ -312,7 +294,7 @@ fn get_cfgs(rustc: &Rustc, target: &Option<String>) -> CargoResult<Option<Vec<Cf
))
}

fn workspace(config: &Config, manifest_path: Option<PathBuf>) -> CargoResult<Workspace> {
fn workspace(config: &Config, manifest_path: Option<PathBuf>) -> CargoResult<Workspace<'_>> {
let root = match manifest_path {
Some(path) => path,
None => important_paths::find_root_manifest_for_wd(config.cwd())?,
Expand Down Expand Up @@ -370,7 +352,7 @@ struct Graph<'a> {

fn build_graph<'a>(
resolve: &'a Resolve,
packages: &'a PackageSet,
packages: &'a PackageSet<'_>,
root: PackageId,
target: Option<&str>,
cfgs: Option<&[Cfg]>,
Expand Down

0 comments on commit 625b33d

Please sign in to comment.