evcxr/
lib.rs

1// Copyright 2020 The Evcxr Authors.
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE or
4// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE
5// or https://opensource.org/licenses/MIT>, at your option. This file may not be
6// copied, modified, or distributed except according to those terms.
7
8#[cfg(all(unix, not(target_os = "freebsd")))]
9#[macro_use]
10extern crate sig;
11
12#[macro_use]
13mod errors;
14mod cargo_metadata;
15mod child_process;
16mod code_block;
17mod command_context;
18mod crash_guard;
19mod crate_config;
20mod eval_context;
21#[allow(dead_code)]
22mod evcxr_internal_runtime;
23mod item;
24mod module;
25mod runtime;
26mod rust_analyzer;
27mod statement_splitter;
28mod toml_parse;
29mod use_trees;
30
31pub use crate::command_context::CommandContext;
32pub use crate::errors::CompilationError;
33pub use crate::errors::Error;
34pub use crate::errors::Theme;
35pub use crate::eval_context::EvalCallbacks;
36pub use crate::eval_context::EvalContext;
37pub use crate::eval_context::EvalContextOutputs;
38pub use crate::eval_context::EvalOutputs;
39pub use crate::runtime::runtime_hook;
40pub use rust_analyzer::Completions;
41
42/// Return the directory that evcxr tools should use for their configuration.
43///
44/// By default this is the `evcxr` subdirectory of whatever `dirs::config_dir()`
45/// returns, but it can be overridden by the `EVCXR_CONFIG_DIR` environment
46/// variable.
47pub fn config_dir() -> Option<std::path::PathBuf> {
48    std::env::var_os("EVCXR_CONFIG_DIR")
49        .map(std::path::PathBuf::from)
50        .or_else(|| dirs::config_dir().map(|d| d.join("evcxr")))
51}