diff options
author | Pascal Kuthe | 2023-01-24 16:07:01 +0000 |
---|---|---|
committer | GitHub | 2023-01-24 16:07:01 +0000 |
commit | e9dc9f493554bd54ea3710e66a2fb0fd2e70b462 (patch) | |
tree | 0b862501d0f5613a3c8dfe47789219ad985e0440 /helix-loader | |
parent | 64ec0256d3e41d6b6e5a24f749489880a147ab8a (diff) |
Switch from toml::from_slice to toml::from_str (#5659)
Diffstat (limited to 'helix-loader')
-rw-r--r-- | helix-loader/src/config.rs | 9 | ||||
-rw-r--r-- | helix-loader/src/lib.rs | 12 |
2 files changed, 14 insertions, 7 deletions
diff --git a/helix-loader/src/config.rs b/helix-loader/src/config.rs index 259b1318..a4c6dcbd 100644 --- a/helix-loader/src/config.rs +++ b/helix-loader/src/config.rs @@ -1,6 +1,9 @@ +use std::str::from_utf8; + /// Default built-in languages.toml. pub fn default_lang_config() -> toml::Value { - toml::from_slice(include_bytes!("../../languages.toml")) + let default_config = include_bytes!("../../languages.toml"); + toml::from_str(from_utf8(default_config).unwrap()) .expect("Could not parse built-in languages.toml to valid toml") } @@ -11,8 +14,8 @@ pub fn user_lang_config() -> Result<toml::Value, toml::de::Error> { .chain([crate::config_dir()].into_iter()) .map(|path| path.join("languages.toml")) .filter_map(|file| { - std::fs::read(&file) - .map(|config| toml::from_slice(&config)) + std::fs::read_to_string(&file) + .map(|config| toml::from_str(&config)) .ok() }) .collect::<Result<Vec<_>, _>>()? diff --git a/helix-loader/src/lib.rs b/helix-loader/src/lib.rs index 80d44a82..8dc2928a 100644 --- a/helix-loader/src/lib.rs +++ b/helix-loader/src/lib.rs @@ -179,6 +179,8 @@ pub fn merge_toml_values(left: toml::Value, right: toml::Value, merge_depth: usi #[cfg(test)] mod merge_toml_tests { + use std::str; + use super::merge_toml_values; use toml::Value; @@ -191,8 +193,9 @@ mod merge_toml_tests { indent = { tab-width = 4, unit = " ", test = "aaa" } "#; - let base: Value = toml::from_slice(include_bytes!("../../languages.toml")) - .expect("Couldn't parse built-in languages config"); + let base = include_bytes!("../../languages.toml"); + let base = str::from_utf8(base).expect("Couldn't parse built-in languages config"); + let base: Value = toml::from_str(base).expect("Couldn't parse built-in languages config"); let user: Value = toml::from_str(USER).unwrap(); let merged = merge_toml_values(base, user, 3); @@ -224,8 +227,9 @@ mod merge_toml_tests { language-server = { command = "deno", args = ["lsp"] } "#; - let base: Value = toml::from_slice(include_bytes!("../../languages.toml")) - .expect("Couldn't parse built-in languages config"); + let base = include_bytes!("../../languages.toml"); + let base = str::from_utf8(base).expect("Couldn't parse built-in languages config"); + let base: Value = toml::from_str(base).expect("Couldn't parse built-in languages config"); let user: Value = toml::from_str(USER).unwrap(); let merged = merge_toml_values(base, user, 3); |