mirror of
https://github.com/robertwayne/axum-htmx
synced 2024-11-24 04:12:50 +01:00
Merge pull request #6 from robertwayne/axum-0.7
Migrate main to axum 0.7 instead of the unstable git branch
This commit is contained in:
commit
c546f23fd0
4 changed files with 37 additions and 15 deletions
|
@ -1,5 +1,11 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## v0.5.0
|
||||||
|
|
||||||
|
- Add `From` impls for `HxResponseTrigger`, `HxResponseTriggerAfterSettle`, and
|
||||||
|
`HxResponseTriggerAfterSwap`, allowing them to take any iterator where `T:
|
||||||
|
Into<String>`.
|
||||||
|
|
||||||
## v0.4.0
|
## v0.4.0
|
||||||
|
|
||||||
- Added support for all [htmx response
|
- Added support for all [htmx response
|
||||||
|
|
|
@ -16,7 +16,7 @@ guards = ["tower", "futures-core", "pin-project-lite"]
|
||||||
serde = ["dep:serde", "dep:serde_json"]
|
serde = ["dep:serde", "dep:serde_json"]
|
||||||
|
|
||||||
[dependencies]
|
[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.
|
# Optional dependencies required for the `guards` feature.
|
||||||
tower = { version = "0.4", default-features = false, optional = true }
|
tower = { version = "0.4", default-features = false, optional = true }
|
||||||
|
|
14
README.md
14
README.md
|
@ -38,15 +38,6 @@
|
||||||
|
|
||||||
Simply run `cargo add axum-htmx` to add the library to your project.
|
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
|
## Extractors
|
||||||
|
|
||||||
All of the [htmx request headers](https://htmx.org/reference/#request_headers)
|
All of the [htmx request headers](https://htmx.org/reference/#request_headers)
|
||||||
|
@ -155,7 +146,8 @@ async fn index() -> (&'static str, HxResponseTrigger) {
|
||||||
can use via the `serde` feature flag and the `HxEvent` type.
|
can use via the `serde` feature flag and the `HxEvent` type.
|
||||||
|
|
||||||
```rust
|
```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
|
// Note that we are using `HxResponseTrigger` from the `axum_htmx::serde` module
|
||||||
// instead of the root module.
|
// instead of the root module.
|
||||||
|
@ -171,7 +163,7 @@ async fn index() -> (&'static str, HxResponseTrigger) {
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
("Hello, world!", HxResponseTrigger(event))
|
("Hello, world!", HxResponseTrigger(vec![event]))
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -220,9 +220,13 @@ impl IntoResponseParts for HxReselect {
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct HxResponseTrigger(pub Vec<String>);
|
pub struct HxResponseTrigger(pub Vec<String>);
|
||||||
|
|
||||||
impl HxResponseTrigger {
|
impl<T> From<T> for HxResponseTrigger
|
||||||
pub fn new(events: &[&str]) -> Self {
|
where
|
||||||
Self(events.iter().map(|e| e.to_string()).collect())
|
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)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct HxResponseTriggerAfterSettle(pub Vec<String>);
|
pub struct HxResponseTriggerAfterSettle(pub Vec<String>);
|
||||||
|
|
||||||
|
impl<T> From<T> 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 {
|
impl IntoResponseParts for HxResponseTriggerAfterSettle {
|
||||||
type Error = HxError;
|
type Error = HxError;
|
||||||
|
|
||||||
|
@ -289,6 +303,16 @@ impl IntoResponseParts for HxResponseTriggerAfterSettle {
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct HxResponseTriggerAfterSwap(pub Vec<String>);
|
pub struct HxResponseTriggerAfterSwap(pub Vec<String>);
|
||||||
|
|
||||||
|
impl<T> From<T> 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 {
|
impl IntoResponseParts for HxResponseTriggerAfterSwap {
|
||||||
type Error = HxError;
|
type Error = HxError;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue