summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2025-09-09 02:31:58 -0400
committerpommicket <pommicket@gmail.com>2025-09-09 02:31:58 -0400
commit323fbd1a50643e6834f66de22d7524979ee5bff7 (patch)
tree526b10c44063012f9beb2760376455892cc958e2 /src/lib.rs
parentae09ca3edfed42519192e8070f34bb5d5ee7c2ec (diff)
Various fixes, misc() test for stuff not in spec tests
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 7d90ec4..77990bf 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -5,7 +5,6 @@
#![warn(clippy::redundant_closure_for_method_calls)]
extern crate alloc;
-use alloc::borrow::ToOwned;
use alloc::boxed::Box;
use alloc::string::String;
use alloc::sync::Arc;
@@ -698,7 +697,10 @@ impl Configuration {
let start_idx = self.subkey_start_idx(key);
let end_idx = self.subkey_end_idx(key);
Configuration {
- items: self.items[start_idx..end_idx].to_owned(),
+ items: self.items[start_idx..end_idx]
+ .iter()
+ .map(|(k, v)| (k[key.len() + 1..].into(), v.clone()))
+ .collect(),
}
}
@@ -855,17 +857,25 @@ impl Configuration {
/// Get value associated with `key`, and parse it as a comma-separated list, or else use `default`.
///
+ /// If you want `default = []`, use [`Self::get_list_or_empty`] instead
+ /// (this method will be cumbersome to use since Rust can't infer the type of `[]`).
+ ///
/// Commas in list entries can be escaped with `\,`.
///
- /// `default` can be anything that can be converted into an iterator of strings,
- /// e.g. `Vec<&str>`, `Vec<String>`, `&[&str]`, etc.
+ /// `default` can be any iterable-of-strings
+ /// (e.g. `&[&str]`, `Vec<String>`, etc.).
pub fn get_list_or_default<L>(&self, key: &str, default: L) -> Vec<String>
where
L: IntoIterator,
- L::Item: AsRef<str>,
+ String: From<L::Item>,
{
self.get_list(key)
- .unwrap_or_else(|| default.into_iter().map(|s| s.as_ref().to_owned()).collect())
+ .unwrap_or_else(|| default.into_iter().map(String::from).collect())
+ }
+ /// Get value associated with `key`, and parse it as a comma-separated list, or else use `[]`.
+ pub fn get_list_or_empty(&self, key: &str) -> Vec<String> {
+ let empty: [&'static str; 0] = [];
+ self.get_list_or_default(key, empty)
}
/// Merge `conf` into `self`, preferring values in `conf`.
@@ -894,7 +904,7 @@ impl Configuration {
}
}
-/// Opaque type returned by [`<&Configuration>::into_iter`].
+/// Opaque type returned by [`Configuration::iter`].
#[derive(Clone, Debug)]
pub struct ConfigurationIter<'a>(core::slice::Iter<'a, (Box<str>, Value)>);