Skip to main content

v_utils/
lib.rs

1#![allow(clippy::get_first)]
2#![allow(clippy::len_zero)]
3#![allow(clippy::tabs_in_doc_comments)]
4#![feature(stmt_expr_attributes)]
5#![feature(specialization)]
6#![allow(incomplete_features)]
7
8#[cfg(all(feature = "assert-wasm-compat", feature = "async-io"))]
9compile_error!("Feature `async-io` is not compatible with wasm.");
10
11#[cfg(all(feature = "assert-wasm-compat", feature = "full"))]
12compile_error!("Feature `full` is not compatible with wasm (pulls in console-subscriber with mio).");
13
14#[cfg(all(feature = "assert-wasm-compat", feature = "xdg"))]
15compile_error!("Feature `xdg` is not compatible with wasm.");
16
17pub mod arch;
18#[cfg(feature = "bevy")]
19pub mod bevy;
20// of course it's included unconditionally - the crate itself is called "v_utils"
21pub mod utils;
22
23#[cfg(feature = "io")]
24pub mod io;
25pub mod other;
26#[cfg(feature = "lite")]
27pub mod prelude;
28#[cfg(feature = "trades")]
29pub mod trades;
30#[doc(hidden)]
31pub mod __internal {
32	pub extern crate eyre;
33	pub extern crate serde;
34
35	#[cfg(feature = "wasm")]
36	pub extern crate console_error_panic_hook;
37	#[cfg(feature = "wasm")]
38	pub extern crate console_log;
39
40	#[cfg(feature = "cli")]
41	pub extern crate config;
42	#[cfg(feature = "cli")]
43	pub extern crate facet;
44	#[cfg(feature = "cli")]
45	pub extern crate facet_json;
46	#[cfg(feature = "cli")]
47	pub extern crate facet_toml;
48	#[cfg(feature = "cli")]
49	pub extern crate serde_json;
50	#[cfg(feature = "cli")]
51	pub extern crate toml;
52
53	#[cfg(feature = "xdg")]
54	pub extern crate xdg;
55
56	#[cfg(all(feature = "io", not(target_arch = "wasm32")))]
57	pub use crate::io::xdg::{home_dir, xdg_cache_fallback, xdg_config_fallback, xdg_data_fallback, xdg_runtime_fallback, xdg_state_fallback};
58
59	#[cfg(feature = "cli")]
60	#[derive(Debug, thiserror::Error)]
61	pub enum SettingsError {
62		#[error("Found multiple config files:\n{}\n\nPlease keep only one. Pick a location, merge all settings into it, then delete the rest.", .paths.iter().map(|p| format!("  - {}", p.display())).collect::<Vec<_>>().join("\n"))]
63		MultipleConfigs { paths: Vec<std::path::PathBuf> },
64		/// NB: no `#[from]`/`#[source]` — these are terminal error messages, not chain links.
65		/// With `#[from]`, thiserror sets `source()` to the inner type, which causes
66		/// `format_eyre_chain_for_user` to print the same message twice (once as root, once as wrapper).
67		#[error("{0}")]
68		Parse(crate::__internal::config::ConfigError),
69		#[error("{0}")]
70		Other(crate::__internal::eyre::Report),
71	}
72	#[cfg(feature = "cli")]
73	impl From<crate::__internal::config::ConfigError> for SettingsError {
74		fn from(e: crate::__internal::config::ConfigError) -> Self {
75			Self::Parse(e)
76		}
77	}
78	#[cfg(feature = "cli")]
79	impl From<crate::__internal::eyre::Report> for SettingsError {
80		fn from(e: crate::__internal::eyre::Report) -> Self {
81			Self::Other(e)
82		}
83	}
84
85	#[cfg(feature = "cli")]
86	impl crate::utils::SysexitCode for SettingsError {
87		fn sysexit(&self) -> crate::utils::Sysexit {
88			crate::utils::Sysexit::Config
89		}
90	}
91}
92#[cfg(feature = "distributions")]
93pub mod distributions;
94#[cfg(test)]
95pub(crate) mod internal_utils;
96
97//Q: I like the idea of having a prelude, but atm it just leads to possibility of mismatching def paths, client imports v_utils and something else relying on a different version of v_utils
98
99pub use other::*;
100
101#[cfg(feature = "macros")]
102pub extern crate v_utils_macros as macros;