Skip to content

Commit

Permalink
wording, style, spelling
Browse files Browse the repository at this point in the history
  • Loading branch information
jordens committed Sep 30, 2024
1 parent 73ab471 commit f089212
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 23 deletions.
9 changes: 6 additions & 3 deletions miniconf/examples/cli.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
use anyhow::{Context, Result};
use anyhow::Context;
use miniconf::{Error, JsonCoreSlash, Path, Traversal, TreeKey};

mod common;
use common::Settings;

fn main() -> Result<()> {
// Simple command line interface example for miniconf.
// This exposes all leaf nodes as long options, parses the command line,
// and then prints the settings struct as a list of option key-value pairs.

fn main() -> anyhow::Result<()> {
let mut settings = Settings::default();
settings.enable();

Expand All @@ -15,7 +19,6 @@ fn main() -> Result<()> {
let value = args.next().context("missing value")?;
settings
.set_json_by_key(&Path::<_, '-'>(key), value.as_bytes())
.map_err(anyhow::Error::msg)
.context("lookup/deserialize")?;
}

Expand Down
2 changes: 1 addition & 1 deletion miniconf/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Display for Traversal {
write!(f, "Variant absent (depth: {depth})")
}
Traversal::TooShort(depth) => {
write!(f, "Key does not read a leaf (depth: {depth})")
write!(f, "Key does not reach a leaf (depth: {depth})")
}
Traversal::NotFound(depth) => {
write!(f, "Key not found (depth: {depth})")
Expand Down
2 changes: 1 addition & 1 deletion miniconf/src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ where
Some(Err(depth))
}
// TooLong: impossible due to Consume
// Absent, Finalization, Invalid, Access: not returned by traverse(traverse_by_key())
// Absent, Finalization, Invalid, Access: not returned by transcode (traverse_by_key())
_ => unreachable!(),
};
}
Expand Down
1 change: 1 addition & 0 deletions miniconf_mqtt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ embedded-io = "0.6"
log = "0.4"
heapless = "0.8"
serde-json-core = "0.6.0"
strum = { version = "0.26.3", features = ["derive"] }

[[example]]
name = "mqtt"
Expand Down
29 changes: 11 additions & 18 deletions miniconf_mqtt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use minimq::{
types::{Properties, SubscriptionOptions, TopicFilter},
ConfigBuilder, DeferredPublication, ProtocolError, Publication, QoS,
};
use strum::IntoStaticStr;

use embedded_io::Write;

Expand All @@ -33,8 +34,6 @@ const DUMP_TIMEOUT_SECONDS: u32 = 2;

const SEPARATOR: char = '/';

type Iter<M, const Y: usize> = NodeIter<M, Y, Path<String<MAX_TOPIC_LENGTH>, SEPARATOR>>;

/// Miniconf MQTT joint error type
#[derive(Debug, PartialEq)]
pub enum Error<E> {
Expand Down Expand Up @@ -114,7 +113,7 @@ mod sm {

/// Cache correlation data and topic for multi-part responses.
struct Multipart<M, const Y: usize> {
iter: Iter<M, Y>,
iter: NodeIter<M, Y, Path<String<MAX_TOPIC_LENGTH>, SEPARATOR>>,
response_topic: Option<String<MAX_TOPIC_LENGTH>>,
correlation_data: Option<Vec<u8, MAX_CD_LENGTH>>,
}
Expand Down Expand Up @@ -164,7 +163,7 @@ impl<M: TreeKey<Y>, const Y: usize> TryFrom<&minimq::types::Properties<'_>> for
}
}

#[derive(Debug, Copy, Clone, PartialEq)]
#[derive(Debug, Copy, Clone, PartialEq, IntoStaticStr)]
enum ResponseCode {
Ok,
Continue,
Expand All @@ -173,15 +172,9 @@ enum ResponseCode {

impl From<ResponseCode> for minimq::Property<'static> {
fn from(value: ResponseCode) -> Self {
let string = match value {
ResponseCode::Ok => "Ok",
ResponseCode::Continue => "Continue",
ResponseCode::Error => "Error",
};

minimq::Property::UserProperty(
minimq::types::Utf8String("code"),
minimq::types::Utf8String(string),
minimq::types::Utf8String(value.into()),
)
}
}
Expand Down Expand Up @@ -342,7 +335,7 @@ where
}
}
// All states must handle MQTT traffic.
self.poll(settings).map(|c| c == Changed::Changed)
self.poll(settings).map(|c| c == State::Changed)
}

fn alive(&mut self) -> Result<(), minimq::PubError<Stack::Error, ()>> {
Expand Down Expand Up @@ -500,7 +493,7 @@ where
})
}

fn poll(&mut self, settings: &mut Settings) -> Result<Changed, Error<Stack::Error>> {
fn poll(&mut self, settings: &mut Settings) -> Result<State, Error<Stack::Error>> {
let Self {
mqtt,
state,
Expand All @@ -515,7 +508,7 @@ where
.map(Path::<_, SEPARATOR>::from)
else {
info!("Unexpected topic: {topic}");
return Changed::Unchanged;
return State::Unchanged;
};

if payload.is_empty() {
Expand Down Expand Up @@ -562,7 +555,7 @@ where
}
}
}
Changed::Unchanged
State::Unchanged
} else {
// Set
settings
Expand All @@ -578,21 +571,21 @@ where
minimq::Error::SessionReset => {
warn!("Session reset");
self.state.process_event(sm::Events::Reset).unwrap();
Ok(Changed::Unchanged)
Ok(State::Unchanged)
}
other => Err(other.into()),
})
}
}

#[derive(Default, Copy, Clone, PartialEq, PartialOrd)]
enum Changed {
enum State {
#[default]
Unchanged,
Changed,
}

impl From<bool> for Changed {
impl From<bool> for State {
fn from(value: bool) -> Self {
if value {
Self::Changed
Expand Down

0 comments on commit f089212

Please sign in to comment.