1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// SPDX-License-Identifier: GPL-3.0-only
// SPDX-FileCopyrightText: Oliver Tale-Yazdi <oliver@tasty.limo>

#![doc = include_str!("../README.md")]

pub mod autofix;
pub mod cmd;
pub mod config;
pub mod dag;
pub mod grammar;
pub mod mock;
mod tests;

pub mod prelude {
	pub use super::{
		dag::{Dag, Path},
		CrateId,
	};
}

/// Unique Id of a Rust crate.
///
/// These come in the form of:
/// `<NAME> <VERSION> (<SOURCE>)`  
/// You can get an idea by using `cargo metadata | jq '.packages' | grep '"id"'`.
pub type CrateId = String;

/// Internal use only.
pub mod log {
	pub use crate::{debug, error, info, trace, warn};
}

#[macro_export]
macro_rules! info {
	($($arg:tt)*) => {
		#[cfg(feature = "logging")]
		{
			::log::info!($($arg)*);
		}
	};
}

#[macro_export]
macro_rules! warn {
	($($arg:tt)*) => {
		#[cfg(feature = "logging")]
		{
			::log::warn!($($arg)*);
		}
	};
}

#[macro_export]
macro_rules! error {
	($($arg:tt)*) => {
		#[cfg(feature = "logging")]
		{
			::log::error!($($arg)*);
		}
	};
}

#[macro_export]
macro_rules! debug {
	($($arg:tt)*) => {
		#[cfg(feature = "logging")]
		{
			::log::debug!($($arg)*);
		}
	};
}

#[macro_export]
macro_rules! trace {
	($($arg:tt)*) => {
		#[cfg(feature = "logging")]
		{
			::log::trace!($($arg)*);
		}
	};
}

/// Convert the error or a `Result` into a `String` error.
pub(crate) trait ErrToStr<R> {
	fn err_to_str(self) -> Result<R, String>;
}

impl<R, E: std::fmt::Display> ErrToStr<R> for Result<R, E> {
	fn err_to_str(self) -> Result<R, String> {
		self.map_err(|e| format!("{}", e))
	}
}

use cargo_metadata::DependencyKind;

pub(crate) fn kind_to_str(kind: &DependencyKind) -> &'static str {
	match kind {
		DependencyKind::Development => "dev-dependencies",
		DependencyKind::Build => "build-dependencies",
		DependencyKind::Normal => "dependencies",
		_ => unreachable!(),
	}
}