Skip to content

Commit c0e7571

Browse files
authored
Merge pull request #5 from quartiq/feature/doc-cleanup
Preparing for 0.1 release
2 parents 957c887 + 507f002 commit c0e7571

File tree

4 files changed

+94
-19
lines changed

4 files changed

+94
-19
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6+
7+
## [Unreleased]
8+
9+
### Added
10+
11+
## [0.1.0] - 2022-03-28
12+
13+
Library initially released on crates.io
14+
15+
[Unreleased]: https://github.com/quartiq/minireq/compare/v0.1.0...HEAD
16+
[0.1.0]: https://github.com/quartiq/minireq/releases/tag/v0.1.0

Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
name = "minireq"
33
version = "0.1.0"
44
edition = "2021"
5-
6-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
5+
authors = ["Ryan Summers <ryan.summers@vertigo-designs.com>"]
6+
license = "MIT"
7+
description = "Lightweight support for MQTT-based request/response handling interfaces"
8+
keywords = ["request", "embedded", "no_std", "configuration", "mqtt"]
9+
categories = ["no-std", "config", "embedded", "parsing"]
10+
repository = "https://github.com/quartiq/minireq"
711

812
[dependencies]
913
minimq = "0.5"
@@ -18,3 +22,4 @@ std-embedded-nal = "0.1"
1822
std-embedded-time = "0.1"
1923
tokio = { version = "1.9", features = ["rt-multi-thread", "time", "macros"] }
2024
env_logger = "0.9"
25+
embedded-nal = "0.6"

src/lib.rs

Lines changed: 71 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,75 @@
11
#![no_std]
2-
/// MQTT Request/response Handling
3-
///
4-
/// # Overview
5-
/// This library is intended to be an easy way to handle inbound requests automatically.
6-
///
7-
/// Handler functions can be associated with the library to be automatically called whenever a
8-
/// specified request is received, and the handler will automatically be invoked when the request
9-
/// is received.
10-
///
11-
/// ## Limitations
12-
/// * The `poll()` function has a somewhat odd signature (using a function to provide the `Context`
13-
/// and call the handler) due to required compatibility with RTIC and unlocked resources.
14-
///
15-
/// * Handlers may only be closures that do not capture any local resources. Instead, move local
16-
/// captures into the `Context`, which will be provided to the handler in the function call.
17-
///
2+
//! MQTT Request/response Handling
3+
//!
4+
//! # Overview
5+
//! This library is intended to be an easy way to handle inbound requests automatically.
6+
//!
7+
//! Handler functions can be associated with the library to be automatically called whenever a
8+
//! specified request is received, and the handler will automatically be invoked with the request
9+
//! data.
10+
//!
11+
//! ## Limitations
12+
//! * The `poll()` function has a somewhat odd signature (using a function to provide the `Context`
13+
//! and call the handler) due to required compatibility with RTIC and unlocked resources.
14+
//!
15+
//! * Handlers may only be closures that do not capture any local resources. Instead, move local
16+
//! captures into the `Context`, which will be provided to the handler in the function call.
17+
//!
18+
//! ## Example
19+
//! ```no_run
20+
//! # use embedded_nal::TcpClientStack;
21+
//! type Error = minireq::Error<
22+
//! // Your network stack error type
23+
//! # <std_embedded_nal::Stack as TcpClientStack>::Error
24+
//! >;
25+
//!
26+
//! struct Context {}
27+
//!
28+
//! #[derive(serde::Serialize, serde::Deserialize)]
29+
//! struct Request {
30+
//! data: u32,
31+
//! }
32+
//!
33+
//! // Handler function for processing an incoming request.
34+
//! pub fn handler(
35+
//! context: &mut Context,
36+
//! cmd: &str,
37+
//! data: &[u8]
38+
//! ) -> Result<minireq::Response<128>, Error> {
39+
//! // Deserialize the request.
40+
//! let mut request: Request = serde_json_core::from_slice(data)?.0;
41+
//!
42+
//! request.data = request.data.wrapping_add(1);
43+
//!
44+
//! Ok(minireq::Response::data(request))
45+
//! }
46+
//!
47+
//! // Construct the client
48+
//! let mut client: minireq::Minireq<Context, _, _, 128, 1> = minireq::Minireq::new(
49+
//! // Constructor arguments
50+
//! # std_embedded_nal::Stack::default(),
51+
//! # "test",
52+
//! # "minireq",
53+
//! # "127.0.0.1".parse().unwrap(),
54+
//! # std_embedded_time::StandardClock::default(),
55+
//! )
56+
//! .unwrap();
57+
//!
58+
//! // Whenever the `/test` command is received, call the associated handler.
59+
//! // You may add as many handlers as you would like.
60+
//! client.register("/test", handler).unwrap();
61+
//!
62+
//! // ...
63+
//!
64+
//! loop {
65+
//! // In your main execution loop, continually poll the client to process incoming requests.
66+
//! client.poll(|handler, command, data| {
67+
//! let mut context = Context {};
68+
//! handler(&mut context, command, data)
69+
//! }).unwrap();
70+
//! }
71+
//! ```
72+
//!
1873
use core::fmt::Write;
1974

2075
use minimq::{

tests/integration.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use minimq;
21
use minireq::Response;
32
use std_embedded_nal::Stack;
43
use std_embedded_time::StandardClock;

0 commit comments

Comments
 (0)