Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove KeyLookup::NAMES and apply dependencies update #231

Merged
merged 4 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased](https://github.com/quartiq/miniconf/compare/v0.13.0...HEAD) - DATE

### Removed

* The `KeyLookup::NAMES` associated constant is now an implementation
detail


## [0.13.0](https://github.com/quartiq/miniconf/compare/v0.12.0...v0.13.0) - 2024-07-10

### Changed
Expand Down
2 changes: 1 addition & 1 deletion miniconf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ resolver = "2"
serde = { version = "1.0.120", default-features = false }
miniconf_derive = { path = "../miniconf_derive", version = "0.13", optional = true }
itoa = "1.0.4"
serde-json-core = { version = "0.5.1", optional = true }
serde-json-core = { version = "0.6.0", optional = true }
postcard = { version = "1.0.8", optional = true }

[features]
Expand Down
1 change: 0 additions & 1 deletion miniconf/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ depth!(2 3 4 5 6 7 8 9 10 11 12 13 14 15 16);

impl<const N: usize, T> KeyLookup for [T; N] {
const LEN: usize = N;
const NAMES: &'static [&'static str] = &[];

fn name_to_index(value: &str) -> Option<usize> {
value.parse().ok()
Expand Down
2 changes: 1 addition & 1 deletion miniconf/src/json_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl<'de, T: TreeSerialize<Y> + TreeDeserialize<'de, Y> + ?Sized, const Y: usize
keys: K,
data: &'de [u8],
) -> Result<usize, Error<de::Error>> {
let mut de: de::Deserializer<'_> = de::Deserializer::new(data);
let mut de = de::Deserializer::new(data, None);
self.deserialize_by_key(keys.into_keys(), &mut de)?;
de.end().map_err(Error::Finalization)
}
Expand Down
6 changes: 0 additions & 6 deletions miniconf/src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::Traversal;
/// bar: [u16; 2],
/// }
/// assert_eq!(S::LEN, 2);
/// assert_eq!(S::NAMES[1], "bar");
/// assert_eq!(S::name_to_index("bar").unwrap(), 1);
/// ```
pub trait KeyLookup {
Expand All @@ -21,11 +20,6 @@ pub trait KeyLookup {
/// This is used by `impl Keys for Packed`.
const LEN: usize;

/// Field names.
///
/// May be empty if `Self` computes and parses names.
const NAMES: &'static [&'static str];

/// Convert a top level node name to a node index.
///
/// The details of the mapping and the `usize` index values
Expand Down
2 changes: 1 addition & 1 deletion miniconf/src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ pub trait TreeDeserialize<'de, const Y: usize = 1>: TreeKey<Y> {
/// bar: [u16; 2],
/// };
/// let mut s = S::default();
/// let mut de = serde_json_core::de::Deserializer::new(b"7");
/// let mut de = serde_json_core::de::Deserializer::new(b"7", None);
/// s.deserialize_by_key(["bar", "0"].into_keys(), &mut de).unwrap();
/// de.end().unwrap();
/// assert_eq!(s.bar[0], 7);
Expand Down
4 changes: 2 additions & 2 deletions miniconf_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ miniconf = { version = "0.13.0", path = "../miniconf", features = [
"postcard",
] }
postcard = "1.0.8"
serde-json-core = "0.5.1"
yafnv = "2.0.0"
serde-json-core = "0.6.0"
yafnv = "3.0.0"

[features]
std = []
Expand Down
2 changes: 1 addition & 1 deletion miniconf_cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ where
Err(miniconf::Error::Traversal(Traversal::Absent(_depth))) => "absent".as_bytes(),
ret => &buf[..ret?],
};
if yafnv::fnv1a::<u32, _>(def) == check {
if yafnv::fnv1a::<u32>(def) == check {
awrite(&mut write, " [default]\n".as_bytes()).await?;
} else {
awrite(&mut write, " [default: ".as_bytes()).await?;
Expand Down
17 changes: 9 additions & 8 deletions miniconf_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub fn derive_tree_key(input: TokenStream) -> TokenStream {
let (names, name_to_index, index_to_name, index_len) =
if fields.iter().all(|f| f.ident.is_none()) {
(
quote!(&[]),
None,
quote!(str::parse(value).ok()),
quote!(if index >= #fields_len {
Err(::miniconf::Traversal::NotFound(1))?
Expand All @@ -44,16 +44,16 @@ pub fn derive_tree_key(input: TokenStream) -> TokenStream {
quote! { stringify!(#name) }
});
(
quote!(&[#(#names ,)*]),
quote!(<Self as ::miniconf::KeyLookup>::NAMES
.iter()
.position(|&n| n == value)),
Some(quote!(
const __MINICONF_NAMES: &'static [&'static str] = &[#(#names ,)*];
)),
quote!(Self::__MINICONF_NAMES.iter().position(|&n| n == value)),
quote!(Some(
*<Self as ::miniconf::KeyLookup>::NAMES
*Self::__MINICONF_NAMES
.get(index)
.ok_or(::miniconf::Traversal::NotFound(1))?
)),
quote!(<Self as ::miniconf::KeyLookup>::NAMES[index].len()),
quote!(Self::__MINICONF_NAMES[index].len()),
)
};

Expand Down Expand Up @@ -85,11 +85,12 @@ pub fn derive_tree_key(input: TokenStream) -> TokenStream {
Ok(index)
}
}

#names
}

impl #impl_generics ::miniconf::KeyLookup for #ident #ty_generics #where_clause {
const LEN: usize = #fields_len;
const NAMES: &'static [&'static str] = #names;

#[inline]
fn name_to_index(value: &str) -> Option<usize> {
Expand Down
6 changes: 3 additions & 3 deletions miniconf_mqtt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ std = []
[dependencies]
miniconf = { version = "0.13", features = ["json-core"], default-features = false, path = "../miniconf" }
minimq = "0.9.0"
smlang = "0.7"
smlang = "0.8"
embedded-io = "0.6"
log = "0.4"
heapless = "0.8"
serde-json-core = "0.5.1"
serde-json-core = "0.6.0"

[[example]]
name = "mqtt"
Expand All @@ -34,5 +34,5 @@ std-embedded-nal = { git = "https://gitlab.com/ryan-summers/std-embedded-nal", b
tokio = { version = "1.9", features = ["rt-multi-thread", "time", "macros"] }
std-embedded-time = "0.1"
miniconf = { features = ["json-core", "derive"], path = "../miniconf" }
serde = { version = "1" }
serde = "1"
heapless = { version = "0.8", features = ["serde"] }
Loading