From 36df71fb2ff17ecc37e7733754f714c878fb9b50 Mon Sep 17 00:00:00 2001 From: Rob Wagner Date: Tue, 24 Oct 2023 00:26:31 -0400 Subject: [PATCH 1/5] Adds a helper From impl for basic HxResponseTrigger* variants. This is purely to help make the public API more friendly and less verbose. --- src/responders.rs | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/responders.rs b/src/responders.rs index c6e273f..778818e 100644 --- a/src/responders.rs +++ b/src/responders.rs @@ -220,9 +220,13 @@ impl IntoResponseParts for HxReselect { #[derive(Debug, Clone)] pub struct HxResponseTrigger(pub Vec); -impl HxResponseTrigger { - pub fn new(events: &[&str]) -> Self { - Self(events.iter().map(|e| e.to_string()).collect()) +impl From for HxResponseTrigger +where + T: IntoIterator, + T::Item: ToString, +{ + fn from(value: T) -> Self { + Self(value.into_iter().map(|s| s.to_string()).collect()) } } @@ -258,6 +262,16 @@ impl IntoResponseParts for HxResponseTrigger { #[derive(Debug, Clone)] pub struct HxResponseTriggerAfterSettle(pub Vec); +impl From for HxResponseTriggerAfterSettle +where + T: IntoIterator, + T::Item: ToString, +{ + fn from(value: T) -> Self { + Self(value.into_iter().map(|s| s.to_string()).collect()) + } +} + impl IntoResponseParts for HxResponseTriggerAfterSettle { type Error = HxError; @@ -289,6 +303,16 @@ impl IntoResponseParts for HxResponseTriggerAfterSettle { #[derive(Debug, Clone)] pub struct HxResponseTriggerAfterSwap(pub Vec); +impl From for HxResponseTriggerAfterSwap +where + T: IntoIterator, + T::Item: ToString, +{ + fn from(value: T) -> Self { + Self(value.into_iter().map(|s| s.to_string()).collect()) + } +} + impl IntoResponseParts for HxResponseTriggerAfterSwap { type Error = HxError; From 138087edc49a7aa36d8b3f85d545fce81a5aa469 Mon Sep 17 00:00:00 2001 From: Rob Wagner Date: Mon, 27 Nov 2023 19:26:50 -0500 Subject: [PATCH 2/5] Update README.md --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7bdb487..ff46ccb 100644 --- a/README.md +++ b/README.md @@ -155,7 +155,8 @@ async fn index() -> (&'static str, HxResponseTrigger) { can use via the `serde` feature flag and the `HxEvent` type. ```rust -use axum_htmx::HxEvent; +use axum_htmx::serde::HxEvent; +use serde_json::json; // Note that we are using `HxResponseTrigger` from the `axum_htmx::serde` module // instead of the root module. @@ -171,7 +172,7 @@ async fn index() -> (&'static str, HxResponseTrigger) { ) .unwrap(); - ("Hello, world!", HxResponseTrigger(event)) + ("Hello, world!", HxResponseTrigger(vec![event])) } ``` From a5928f10a622059c08a72a07d793a4031928802b Mon Sep 17 00:00:00 2001 From: Rob Wagner Date: Mon, 27 Nov 2023 19:27:05 -0500 Subject: [PATCH 3/5] Update axum to 0.7 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 6b97b68..c898f59 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ guards = ["tower", "futures-core", "pin-project-lite"] serde = ["dep:serde", "dep:serde_json"] [dependencies] -axum = { git = "https://github.com/tokio-rs/axum", branch = "main", default-features = false } +axum = { version = "0.7", default-features = false } # Optional dependencies required for the `guards` feature. tower = { version = "0.4", default-features = false, optional = true } From aa9087b76fd2f940c702947810687112caba602e Mon Sep 17 00:00:00 2001 From: Rob Wagner Date: Mon, 27 Nov 2023 19:38:23 -0500 Subject: [PATCH 4/5] Update CHANGELOG.md --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 55ae21b..80bffbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## v0.5.0 + +- Add `From` impls for `HxResponseTrigger`, `HxResponseTriggerAfterSettle`, and + `HxResponseTriggerAfterSwap`, allowing them to take any iterator where `T: + Into`. + ## v0.4.0 - Added support for all [htmx response From 0b7c48043f734dc2aeb38f3d1855755f9d37d8df Mon Sep 17 00:00:00 2001 From: Rob Wagner Date: Mon, 27 Nov 2023 19:40:02 -0500 Subject: [PATCH 5/5] Update README.md --- README.md | 9 --------- 1 file changed, 9 deletions(-) diff --git a/README.md b/README.md index ff46ccb..de08967 100644 --- a/README.md +++ b/README.md @@ -38,15 +38,6 @@ Simply run `cargo add axum-htmx` to add the library to your project. -If you are using the unreleased branch of `axum` from GitHub, you can build -against the `main` version of `axum-htmx` by adding the following to your -`Cargo.toml`: - -```toml -[dependencies] -axum-htmx = { git = "https://github.com/robertwayne/axum-htmx" } -``` - ## Extractors All of the [htmx request headers](https://htmx.org/reference/#request_headers)