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

enum example, py deps #250

Merged
merged 2 commits into from
Oct 15, 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
13 changes: 9 additions & 4 deletions miniconf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ providers are supported.
use serde::{Deserialize, Serialize};
use miniconf::{Error, json, JsonPath, Traversal, Tree, TreeKey, Path, Packed, Node};

#[derive(Deserialize, Serialize, Default)]
#[derive(Deserialize, Serialize, Default, Tree)]
enum Either {
#[default]
Bad,
Good,
A(i32),
B(#[tree(depth=1)] Inner),
C(#[tree(depth=2)] [Inner; 2]),
}

#[derive(Deserialize, Serialize, Default, Tree)]
Expand All @@ -48,6 +51,8 @@ struct Settings {

#[tree(depth=1)]
struct_tree: Inner,
#[tree(depth=3)]
enum_tree: Either,
#[tree(depth=1)]
array_tree: [i32; 2],
#[tree(depth=2)]
Expand Down Expand Up @@ -80,10 +85,10 @@ json::set(&mut settings, "/array_tree/0", b"7")?;
// ... or by index and then struct field name
json::set(&mut settings, "/array_tree2/0/a", b"11")?;
// ... or by hierarchical index
json::set_by_key(&mut settings, [7usize, 0, 1], b"8")?;
json::set_by_key(&mut settings, [8usize, 0, 1], b"8")?;
// ... or by packed index
let (packed, node) = Settings::transcode::<Packed, _>([7usize, 1, 0]).unwrap();
assert_eq!(packed.into_lsb().get(), 0b1_0111_1_0);
let (packed, node) = Settings::transcode::<Packed, _>([8usize, 1, 0]).unwrap();
assert_eq!(packed.into_lsb().get(), 0b1_1000_1_0);
assert_eq!(node, Node::leaf(3));
json::set_by_key(&mut settings, packed, b"9")?;
// ... or by JSON path
Expand Down
8 changes: 7 additions & 1 deletion miniconf/examples/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ use serde::{Deserialize, Serialize};

// Either/Inner/Settings are straight from README.md

#[derive(Deserialize, Serialize, Default)]
#[derive(Deserialize, Serialize, Default, Tree)]
pub enum Either {
#[default]
Bad,
Good,
A(i32),
B(#[tree(depth = 1)] Inner),
C(#[tree(depth = 2)] [Inner; 2]),
}

#[derive(Deserialize, Serialize, Default, Tree)]
Expand All @@ -30,6 +33,8 @@ pub struct Settings {

#[tree(depth = 1)]
struct_tree: Inner,
#[tree(depth = 3)]
enum_tree: Either,
#[tree(depth = 1)]
array_tree: [i32; 2],
#[tree(depth = 2)]
Expand All @@ -47,6 +52,7 @@ impl Settings {
/// Fill some of the Options
pub fn enable(&mut self) {
self.option_tree = Some(8);
self.enum_tree = Either::B(Default::default());
self.option_tree2 = Some(Default::default());
self.array_option_tree[1] = Some(Default::default());
}
Expand Down
2 changes: 1 addition & 1 deletion py/miniconf-mqtt/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ authors = [
{ name = "Ryan Summers", email = "[email protected]" },
{ name = "Robert Jördens", email = "[email protected]" },
]
dependencies = ["aiomqtt >= 2.2.0", "typing_extensions >= 4.12"]
dependencies = ["aiomqtt >= 2.1.0", "typing_extensions >= 4.11"]

[project.urls]
Homepage = "https://github.com/quartiq/miniconf"
Expand Down
Loading