1use std::path::PathBuf;
7
8use serde::{Deserialize, Serialize};
9
10#[derive(Debug, Clone, Default, Serialize, Deserialize)]
12pub struct ZigConfig {
13 #[serde(default)]
14 pub memory: MemorySection,
15}
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
19pub struct MemorySection {
20 #[serde(default = "default_true")]
23 pub local: bool,
24}
25
26fn default_true() -> bool {
27 true
28}
29
30impl Default for MemorySection {
31 fn default() -> Self {
32 Self { local: true }
33 }
34}
35
36impl ZigConfig {
37 pub fn config_path() -> PathBuf {
39 crate::paths::global_base_dir()
40 .unwrap_or_else(|| PathBuf::from(".zig"))
41 .join("config.toml")
42 }
43
44 pub fn load() -> Self {
47 match std::fs::read_to_string(Self::config_path()) {
48 Ok(contents) => toml::from_str(&contents).unwrap_or_default(),
49 Err(_) => Self::default(),
50 }
51 }
52}
53
54#[cfg(test)]
55#[path = "config_tests.rs"]
56mod tests;