Skip to main content

cuprated/
constants.rs

1//! General constants used throughout `cuprated`.
2use std::time::Duration;
3
4use const_format::formatcp;
5
6/// `cuprated`'s semantic version (`MAJOR.MINOR.PATCH`) as string.
7pub const VERSION: &str = clap::crate_version!();
8
9/// Major version number of `cuprated`.
10pub const MAJOR_VERSION: &str = env!("CARGO_PKG_VERSION_MAJOR");
11
12/// Major version number of `cuprated`.
13pub const MINOR_VERSION: &str = env!("CARGO_PKG_VERSION_MINOR");
14
15/// Patch version number of `cuprated`.
16pub const PATCH_VERSION: &str = env!("CARGO_PKG_VERSION_PATCH");
17
18/// [`VERSION`] + the build type.
19///
20/// If a debug build, the suffix is `-debug`, else it is `-release`.
21pub const VERSION_BUILD: &str = formatcp!("{VERSION}-{}", cuprate_constants::build::BUILD);
22
23pub const DEFAULT_CONFIG_WARNING: &str = formatcp!(
24    "WARNING: no config file found, using default config.\
25    \nThe default config may not be optimal for your setup, see the user book here: https://user.cuprate.org/.\
26    \nPausing startup for {} seconds. \
27    \nUse the `--skip-config-warning` arg to skip this delay if you really want to use the default.",
28    DEFAULT_CONFIG_STARTUP_DELAY.as_secs()
29);
30
31pub const DEFAULT_CONFIG_STARTUP_DELAY: Duration = Duration::from_secs(15);
32
33/// Corrupt database error message.
34///
35/// The error message shown to end-users in panic
36/// messages if we think the database is corrupted.
37///
38/// This is meant to be user-friendly.
39pub const DATABASE_CORRUPT_MSG: &str = r"`cuprated` has encountered a fatal error. The database may be corrupted.
40
41If `cuprated` continues to crash with the current database,
42you may have to delete the database file and re-sync from scratch.
43
44See <https://user.cuprate.org/resources/disk.html>
45for more information on where database files are.
46
47If this happens frequently, consider using the `Safe` sync mode.";
48
49#[cfg(test)]
50mod test {
51    use super::*;
52
53    #[test]
54    fn version_build() {
55        if cfg!(debug_assertions) {
56            assert_eq!(VERSION_BUILD, "0.1.0-preview-debug");
57        } else {
58            assert_eq!(VERSION_BUILD, "0.1.0-preview-release");
59        }
60    }
61}