diff --git a/src/responders.rs b/src/responders.rs index beebc10..67b5019 100644 --- a/src/responders.rs +++ b/src/responders.rs @@ -45,6 +45,12 @@ impl IntoResponseParts for HxPushUrl { } } +impl From for HxPushUrl { + fn from(uri: Uri) -> Self { + Self(uri) + } +} + impl<'a> TryFrom<&'a str> for HxPushUrl { type Error = ::Err; @@ -75,6 +81,12 @@ impl IntoResponseParts for HxRedirect { } } +impl From for HxRedirect { + fn from(uri: Uri) -> Self { + Self(uri) + } +} + impl<'a> TryFrom<&'a str> for HxRedirect { type Error = ::Err; @@ -91,6 +103,12 @@ impl<'a> TryFrom<&'a str> for HxRedirect { #[derive(Debug, Copy, Clone)] pub struct HxRefresh(pub bool); +impl From for HxRefresh { + fn from(value: bool) -> Self { + Self(value) + } +} + impl IntoResponseParts for HxRefresh { type Error = Infallible; @@ -132,6 +150,12 @@ impl IntoResponseParts for HxReplaceUrl { } } +impl From for HxReplaceUrl { + fn from(uri: Uri) -> Self { + Self(uri) + } +} + impl<'a> TryFrom<&'a str> for HxReplaceUrl { type Error = ::Err; @@ -158,6 +182,12 @@ impl IntoResponseParts for HxReswap { } } +impl From for HxReswap { + fn from(value: SwapOption) -> Self { + Self(value) + } +} + /// The `HX-Retarget` header. /// /// A CSS selector that updates the target of the content update to a different @@ -181,6 +211,12 @@ impl IntoResponseParts for HxRetarget { } } +impl From for HxRetarget { + fn from(value: String) -> Self { + Self(value) + } +} + /// The `HX-Reselect` header. /// /// A CSS selector that allows you to choose which part of the response is used @@ -204,6 +240,12 @@ impl IntoResponseParts for HxReselect { } } +impl From for HxReselect { + fn from(value: String) -> Self { + Self(value) + } +} + /// Values of the `hx-swap` attribute. // serde::Serialize is implemented in responders/serde.rs #[derive(Debug, Copy, Clone)] diff --git a/src/responders/trigger.rs b/src/responders/trigger.rs index 343d216..e96440b 100644 --- a/src/responders/trigger.rs +++ b/src/responders/trigger.rs @@ -141,6 +141,19 @@ impl HxResponseTrigger { } } +impl From<(TriggerMode, T)> for HxResponseTrigger +where + T: IntoIterator, + T::Item: Into, +{ + fn from((mode, events): (TriggerMode, T)) -> Self { + Self { + mode, + events: events.into_iter().map(Into::into).collect(), + } + } +} + impl IntoResponseParts for HxResponseTrigger { type Error = HxError;