zenoh_util/
lib.rs

1//
2// Copyright (c) 2023 ZettaScale Technology
3//
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7// which is available at https://www.apache.org/licenses/LICENSE-2.0.
8//
9// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
10//
11// Contributors:
12//   ZettaScale Zenoh Team, <zenoh@zettascale.tech>
13//
14
15//! ⚠️ WARNING ⚠️
16//!
17//! This crate is intended for Zenoh's internal use.
18//!
19//! [Click here for Zenoh's documentation](https://docs.rs/zenoh/latest/zenoh)
20use lazy_static::lazy_static;
21
22pub mod ffi;
23mod lib_loader;
24pub mod lib_search_dirs;
25pub mod net;
26pub mod time_range;
27
28pub use lib_loader::*;
29pub mod timer;
30pub use timer::*;
31pub mod log;
32pub use lib_search_dirs::*;
33pub use log::*;
34
35/// The "ZENOH_HOME" environment variable name
36pub const ZENOH_HOME_ENV_VAR: &str = "ZENOH_HOME";
37
38const DEFAULT_ZENOH_HOME_DIRNAME: &str = ".zenoh";
39
40/// Return the path to the ${ZENOH_HOME} directory (~/.zenoh by default).
41pub fn zenoh_home() -> &'static std::path::Path {
42    use std::path::PathBuf;
43    lazy_static! {
44        static ref ROOT: PathBuf = {
45            if let Some(dir) = std::env::var_os(ZENOH_HOME_ENV_VAR) {
46                PathBuf::from(dir)
47            } else {
48                match home::home_dir() {
49                    Some(mut dir) => {
50                        dir.push(DEFAULT_ZENOH_HOME_DIRNAME);
51                        dir
52                    }
53                    None => PathBuf::from(DEFAULT_ZENOH_HOME_DIRNAME),
54                }
55            }
56        };
57    }
58    ROOT.as_path()
59}
60
61#[doc(hidden)]
62pub use const_format::concatcp as __concatcp;
63#[macro_export]
64macro_rules! concat_enabled_features {
65    (prefix = $prefix:literal, features = [$($feature:literal),* $(,)?]) => {
66        {
67            $crate::__concatcp!($(
68                if cfg!(feature = $feature) { $crate::__concatcp!(" ", $prefix, "/", $feature) } else { "" }
69            ),*)
70        }
71    };
72}