mirror of
https://github.com/robertwayne/axum-htmx
synced 2024-11-26 05:09:35 +01:00
Adds a helper From<T> impl for basic HxResponseTrigger* variants.
This is purely to help make the public API more friendly and less verbose.
This commit is contained in:
parent
35aa41f5ba
commit
36df71fb2f
1 changed files with 27 additions and 3 deletions
|
@ -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