]> git.proxmox.com Git - cargo.git/blob - src/cargo/util/mod.rs
Rework test error handling
[cargo.git] / src / cargo / util / mod.rs
1 use std::fmt;
2 use std::time::Duration;
3
4 pub use self::canonical_url::CanonicalUrl;
5 pub use self::config::{homedir, Config, ConfigValue};
6 pub(crate) use self::counter::MetricsCounter;
7 pub use self::dependency_queue::DependencyQueue;
8 pub use self::diagnostic_server::RustfixDiagnosticServer;
9 pub use self::errors::CliError;
10 pub use self::errors::{internal, CargoResult, CliResult};
11 pub use self::flock::{FileLock, Filesystem};
12 pub use self::graph::Graph;
13 pub use self::hasher::StableHasher;
14 pub use self::hex::{hash_u64, short_hash, to_hex};
15 pub use self::into_url::IntoUrl;
16 pub use self::into_url_with_base::IntoUrlWithBase;
17 pub use self::lev_distance::{closest, closest_msg, lev_distance};
18 pub use self::lockserver::{LockServer, LockServerClient, LockServerStarted};
19 pub use self::progress::{Progress, ProgressStyle};
20 pub use self::queue::Queue;
21 pub use self::restricted_names::validate_package_name;
22 pub use self::rustc::Rustc;
23 pub use self::semver_ext::{OptVersionReq, VersionExt, VersionReqExt};
24 pub use self::to_semver::ToSemver;
25 pub use self::vcs::{existing_vcs_repo, FossilRepo, GitRepo, HgRepo, PijulRepo};
26 pub use self::workspace::{
27 add_path_args, path_args, print_available_benches, print_available_binaries,
28 print_available_examples, print_available_packages, print_available_tests,
29 };
30
31 mod canonical_url;
32 pub mod command_prelude;
33 pub mod config;
34 mod counter;
35 pub mod cpu;
36 mod dependency_queue;
37 pub mod diagnostic_server;
38 pub mod errors;
39 mod flock;
40 pub mod graph;
41 mod hasher;
42 pub mod hex;
43 pub mod important_paths;
44 pub mod interning;
45 pub mod into_url;
46 mod into_url_with_base;
47 pub mod job;
48 pub mod lev_distance;
49 mod lockserver;
50 pub mod machine_message;
51 pub mod network;
52 pub mod profile;
53 mod progress;
54 mod queue;
55 pub mod restricted_names;
56 pub mod rustc;
57 mod semver_ext;
58 pub mod to_semver;
59 pub mod toml;
60 mod vcs;
61 mod workspace;
62
63 pub fn elapsed(duration: Duration) -> String {
64 let secs = duration.as_secs();
65
66 if secs >= 60 {
67 format!("{}m {:02}s", secs / 60, secs % 60)
68 } else {
69 format!("{}.{:02}s", secs, duration.subsec_nanos() / 10_000_000)
70 }
71 }
72
73 pub fn iter_join_onto<W, I, T>(mut w: W, iter: I, delim: &str) -> fmt::Result
74 where
75 W: fmt::Write,
76 I: IntoIterator<Item = T>,
77 T: std::fmt::Display,
78 {
79 let mut it = iter.into_iter().peekable();
80 while let Some(n) = it.next() {
81 write!(w, "{}", n)?;
82 if it.peek().is_some() {
83 write!(w, "{}", delim)?;
84 }
85 }
86 Ok(())
87 }
88
89 pub fn iter_join<I, T>(iter: I, delim: &str) -> String
90 where
91 I: IntoIterator<Item = T>,
92 T: std::fmt::Display,
93 {
94 let mut s = String::new();
95 let _ = iter_join_onto(&mut s, iter, delim);
96 s
97 }
98
99 pub fn indented_lines(text: &str) -> String {
100 text.lines()
101 .map(|line| {
102 if line.is_empty() {
103 String::from("\n")
104 } else {
105 format!(" {}\n", line)
106 }
107 })
108 .collect()
109 }