mirror of
https://github.com/NLnetLabs/rtrtr.git
synced 2024-05-11 05:55:07 +00:00
Upgrade toml to 0.8.2. (#91)
This PR upgrades toml to 0.8.2 which requires a few small changes.
This commit is contained in:
75
Cargo.lock
generated
75
Cargo.lock
generated
@ -143,7 +143,7 @@ dependencies = [
|
||||
"atty",
|
||||
"bitflags",
|
||||
"clap_lex",
|
||||
"indexmap",
|
||||
"indexmap 1.9.3",
|
||||
"once_cell",
|
||||
"strsim",
|
||||
"termcolor",
|
||||
@ -202,6 +202,12 @@ dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
|
||||
|
||||
[[package]]
|
||||
name = "error-chain"
|
||||
version = "0.12.4"
|
||||
@ -353,7 +359,7 @@ dependencies = [
|
||||
"futures-sink",
|
||||
"futures-util",
|
||||
"http",
|
||||
"indexmap",
|
||||
"indexmap 1.9.3",
|
||||
"slab",
|
||||
"tokio",
|
||||
"tokio-util",
|
||||
@ -366,6 +372,12 @@ version = "0.12.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.14.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12"
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.1.19"
|
||||
@ -504,7 +516,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"hashbrown",
|
||||
"hashbrown 0.12.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "2.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897"
|
||||
dependencies = [
|
||||
"equivalent",
|
||||
"hashbrown 0.14.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -917,6 +939,15 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_spanned"
|
||||
version = "0.6.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "96426c9936fd7a0124915f9185ea1d20aa9445cc9821142f0a73bc9207a2e186"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_urlencoded"
|
||||
version = "0.7.1"
|
||||
@ -1147,11 +1178,36 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.5.11"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234"
|
||||
checksum = "185d8ab0dfbb35cf1399a6344d8484209c088f75f8f68230da55d48d95d43e3d"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_spanned",
|
||||
"toml_datetime",
|
||||
"toml_edit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_datetime"
|
||||
version = "0.6.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_edit"
|
||||
version = "0.20.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338"
|
||||
dependencies = [
|
||||
"indexmap 2.0.2",
|
||||
"serde",
|
||||
"serde_spanned",
|
||||
"toml_datetime",
|
||||
"winnow",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1439,6 +1495,15 @@ version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
|
||||
|
||||
[[package]]
|
||||
name = "winnow"
|
||||
version = "0.5.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a3b801d0e0a6726477cc207f60162da452f3a95adb368399bef20a946e06f65c"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winreg"
|
||||
version = "0.50.0"
|
||||
|
@ -32,7 +32,7 @@ slab = "0.4.2"
|
||||
tokio = { version = "1.6", features = ["io-util", "macros", "net", "rt", "rt-multi-thread", "sync", "time"]}
|
||||
tokio-rustls = "0.24.1"
|
||||
tokio-stream = { version = "0.1", features = ["net"] }
|
||||
toml = "0.5.6"
|
||||
toml = "0.8.2"
|
||||
url = { version = "2.2", features = ["serde"] }
|
||||
webpki-roots = "0.25.2"
|
||||
|
||||
|
@ -56,12 +56,12 @@ impl Config {
|
||||
|
||||
/// Creates a configuration from a bytes slice with TOML data.
|
||||
pub fn from_toml(
|
||||
slice: &[u8], base_dir: Option<impl AsRef<Path>>,
|
||||
slice: &str, base_dir: Option<impl AsRef<Path>>,
|
||||
) -> Result<Self, toml::de::Error> {
|
||||
if let Some(ref base_dir) = base_dir {
|
||||
ConfigPath::set_base_path(base_dir.as_ref().into())
|
||||
}
|
||||
let res = toml::de::from_slice(slice);
|
||||
let res = toml::de::from_str(slice);
|
||||
ConfigPath::clear_base_path();
|
||||
res
|
||||
}
|
||||
@ -228,7 +228,7 @@ impl<T> From<T> for Marked<T> {
|
||||
impl<T> From<Spanned<T>> for Marked<T> {
|
||||
fn from(src: Spanned<T>) -> Marked<T> {
|
||||
Marked {
|
||||
index: src.start(),
|
||||
index: src.span().start,
|
||||
value: src.into_inner(),
|
||||
source: None, pos: None,
|
||||
}
|
||||
@ -280,7 +280,7 @@ pub struct ConfigFile {
|
||||
source: Source,
|
||||
|
||||
/// The data of this file.
|
||||
bytes: Vec<u8>,
|
||||
bytes: String,
|
||||
|
||||
/// The start indexes of lines.
|
||||
///
|
||||
@ -291,13 +291,14 @@ pub struct ConfigFile {
|
||||
impl ConfigFile {
|
||||
/// Load a config file from disk.
|
||||
pub fn load(path: &impl AsRef<Path>) -> Result<Self, io::Error> {
|
||||
fs::read(path).map(|bytes| {
|
||||
fs::read_to_string(path).map(|bytes| {
|
||||
ConfigFile {
|
||||
source: path.into(),
|
||||
line_starts: bytes.split(|ch| *ch == b'\n').fold(
|
||||
line_starts: bytes.split('\n').fold(
|
||||
vec![0], |mut starts, slice| {
|
||||
starts.push(
|
||||
starts.last().unwrap() + slice.len()
|
||||
// slice doesn’t include the \n
|
||||
starts.last().unwrap() + slice.len() + 1
|
||||
);
|
||||
starts
|
||||
}
|
||||
@ -315,16 +316,21 @@ impl ConfigFile {
|
||||
self.source.path.as_ref().and_then(|path| path.parent())
|
||||
}
|
||||
|
||||
pub fn bytes(&self) -> &[u8] {
|
||||
pub fn bytes(&self) -> &str {
|
||||
&self.bytes
|
||||
}
|
||||
|
||||
fn resolve_pos(&self, pos: usize) -> LineCol {
|
||||
let line = self.line_starts.iter().find(|&&start|
|
||||
start < pos
|
||||
).copied().unwrap_or(self.line_starts.len());
|
||||
let line = self.line_starts.iter().enumerate().find_map(|(i, start)|
|
||||
if *start > pos {
|
||||
Some(i)
|
||||
}
|
||||
else {
|
||||
None
|
||||
}
|
||||
).unwrap_or(self.line_starts.len());
|
||||
let line = line - 1;
|
||||
let col = self.line_starts[line] - pos;
|
||||
let col = pos - self.line_starts[line];
|
||||
LineCol { line, col }
|
||||
}
|
||||
}
|
||||
@ -346,9 +352,9 @@ impl ConfigError {
|
||||
value: (),
|
||||
index: 0,
|
||||
source: Some(file.source.clone()),
|
||||
pos: err.line_col().map(|(line, col)| {
|
||||
LineCol { line: line + 1, col: col + 1 }
|
||||
})
|
||||
pos: err.span().map(|range| {
|
||||
file.resolve_pos(range.start)
|
||||
}),
|
||||
},
|
||||
err,
|
||||
}
|
||||
|
Reference in New Issue
Block a user