From 36df71fb2ff17ecc37e7733754f714c878fb9b50 Mon Sep 17 00:00:00 2001 From: Rob Wagner Date: Tue, 24 Oct 2023 00:26:31 -0400 Subject: [PATCH] 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;