-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
313 additions
and
239 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,40 @@ | ||
use std::sync::Arc; | ||
use std::{collections::HashMap, sync::Arc}; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
use thiserror::Error; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
#[serde(untagged)] | ||
pub enum SharableConfig<T> { | ||
SharingKey(Arc<str>), | ||
Private(T), | ||
} | ||
|
||
pub trait Merge: Default { | ||
type Error; | ||
/// # Error | ||
/// | ||
/// - Attempted key overriding | ||
fn merge(self, other: Self) -> Result<Self, Self::Error> | ||
where | ||
Self: Sized; | ||
} | ||
|
||
pub fn merge_map<K, V>( | ||
mut a: HashMap<K, V>, | ||
b: HashMap<K, V>, | ||
) -> Result<HashMap<K, V>, RepeatKeyMergeError<K>> | ||
where | ||
K: Eq + std::hash::Hash, | ||
{ | ||
for (k, v) in b { | ||
if a.contains_key(&k) { | ||
return Err(RepeatKeyMergeError(k)); | ||
} | ||
a.insert(k, v); | ||
} | ||
Ok(a) | ||
} | ||
#[derive(Debug, Error)] | ||
#[error("Repeated key: {0}")] | ||
pub struct RepeatKeyMergeError<K>(pub K); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
pub fn human_toml_error(file_path: &str, src: &str, e: toml::de::Error) -> String { | ||
let Some(span) = e.span() else { | ||
return format!("{e}"); | ||
}; | ||
let affected = src | ||
.chars() | ||
.skip(span.start) | ||
.take(span.end - span.start) | ||
.collect::<String>(); | ||
let (line, col) = { | ||
let mut line = 1; | ||
let mut col = 1; | ||
|
||
for (i, char) in src.chars().enumerate() { | ||
if i == span.start { | ||
break; | ||
} | ||
if char == '\n' { | ||
line += 1; | ||
col = 1; | ||
} | ||
col += 1; | ||
} | ||
|
||
(line, col) | ||
}; | ||
let msg = e.message(); | ||
let e = format!( | ||
"{msg} | ||
File `{file_path}` | ||
Line {line}, Column {col} | ||
Affected: #'{affected}'#" | ||
); | ||
e | ||
} |
Oops, something went wrong.