diff --git a/src/responders.rs b/src/responders.rs
index 9a2cf34..1766d12 100644
--- a/src/responders.rs
+++ b/src/responders.rs
@@ -21,9 +21,13 @@ const HX_SWAP_NONE: &str = "none";
/// The `HX-Location` header.
///
-/// This response header can be used to trigger a client side redirection without reloading the whole page.
+/// This response header can be used to trigger a client side redirection
+/// without reloading the whole page.
///
-/// Will fail if the supplied Uri contains characters that are not visible ASCII (32-127).
+/// Will fail if the supplied Uri contains characters that are not visible ASCII
+/// (32-127).
+///
+/// See for more information.
#[derive(Debug, Clone)]
pub struct HxLocation(pub Uri);
@@ -35,6 +39,7 @@ impl IntoResponseParts for HxLocation {
headers::HX_LOCATION,
HeaderValue::from_maybe_shared(self.0.to_string())?,
);
+
Ok(res)
}
}
@@ -43,7 +48,8 @@ impl IntoResponseParts for HxLocation {
///
/// Pushes a new url into the history stack.
///
-/// Will fail if the supplied Uri contains characters that are not visible ASCII (32-127).
+/// Will fail if the supplied Uri contains characters that are not visible ASCII
+/// (32-127).
#[derive(Debug, Clone)]
pub struct HxPushUrl(pub Uri);
@@ -55,6 +61,7 @@ impl IntoResponseParts for HxPushUrl {
headers::HX_PUSH_URL,
HeaderValue::from_maybe_shared(self.0.to_string())?,
);
+
Ok(res)
}
}
@@ -63,7 +70,8 @@ impl IntoResponseParts for HxPushUrl {
///
/// Can be used to do a client-side redirect to a new location.
///
-/// Will fail if the supplied Uri contains characters that are not visible ASCII (32-127).
+/// Will fail if the supplied Uri contains characters that are not visible ASCII
+/// (32-127).
#[derive(Debug, Clone)]
pub struct HxRedirect(pub Uri);
@@ -75,6 +83,7 @@ impl IntoResponseParts for HxRedirect {
headers::HX_REDIRECT,
HeaderValue::from_maybe_shared(self.0.to_string())?,
);
+
Ok(res)
}
}
@@ -98,6 +107,7 @@ impl IntoResponseParts for HxRefresh {
false => HeaderValue::from_static("false"),
},
);
+
Ok(res)
}
}
@@ -106,7 +116,8 @@ impl IntoResponseParts for HxRefresh {
///
/// Replaces the currelt URL in the location bar.
///
-/// Will fail if the supplied Uri contains characters that are not visible ASCII (32-127).
+/// Will fail if the supplied Uri contains characters that are not visible ASCII
+/// (32-127).
#[derive(Debug, Clone)]
pub struct HxReplaceUrl(pub Uri);
@@ -118,6 +129,7 @@ impl IntoResponseParts for HxReplaceUrl {
headers::HX_REPLACE_URL,
HeaderValue::from_maybe_shared(self.0.to_string())?,
);
+
Ok(res)
}
}
@@ -135,15 +147,18 @@ impl IntoResponseParts for HxReswap {
fn into_response_parts(self, mut res: ResponseParts) -> Result {
res.headers_mut().insert(headers::HX_RESWAP, self.0.into());
+
Ok(res)
}
}
/// The `HX-Retarget` header.
///
-/// A CSS selector that updates the target of the content update to a different element on the page.
+/// A CSS selector that updates the target of the content update to a different
+/// element on the page.
///
-/// Will fail if the supplied String contains characters that are not visible ASCII (32-127).
+/// Will fail if the supplied String contains characters that are not visible
+/// ASCII (32-127).
#[derive(Debug, Clone)]
pub struct HxRetarget(pub String);
@@ -155,15 +170,18 @@ impl IntoResponseParts for HxRetarget {
headers::HX_RETARGET,
HeaderValue::from_maybe_shared(self.0)?,
);
+
Ok(res)
}
}
/// The `HX-Reselect` header.
///
-/// A CSS selector that allows you to choose which part of the response is used to be swapped in. Overrides an existing hx-select on the triggering element.
+/// A CSS selector that allows you to choose which part of the response is used
+/// to be swapped in. Overrides an existing hx-select on the triggering element.
///
-/// Will fail if the supplied String contains characters that are not visible ASCII (32-127).
+/// Will fail if the supplied String contains characters that are not visible
+/// ASCII (32-127).
#[derive(Debug, Clone)]
pub struct HxReselect(pub String);
@@ -175,6 +193,7 @@ impl IntoResponseParts for HxReselect {
headers::HX_RESELECT,
HeaderValue::from_maybe_shared(self.0)?,
);
+
Ok(res)
}
}
@@ -183,7 +202,8 @@ impl IntoResponseParts for HxReselect {
///
/// Allows you to trigger client-side events.
///
-/// Will fail if the supplied events contain or produce characters that are not visible ASCII (32-127) when serializing to json.
+/// Will fail if the supplied events contain or produce characters that are not
+/// visible ASCII (32-127) when serializing to json.
#[derive(Debug, Clone)]
pub struct HxResponseTrigger(pub Vec);
@@ -200,6 +220,7 @@ impl IntoResponseParts for HxResponseTrigger {
.unwrap_or_default(),
)?,
);
+
Ok(res)
}
}
@@ -208,7 +229,8 @@ impl IntoResponseParts for HxResponseTrigger {
///
/// Allows you to trigger client-side events after the settle step.
///
-/// Will fail if the supplied events contain or produce characters that are not visible ASCII (32-127) when serializing to json.
+/// Will fail if the supplied events contain or produce characters that are not
+/// visible ASCII (32-127) when serializing to json.
#[derive(Debug, Clone)]
pub struct HxResponseTriggerAfterSettle(pub Vec);
@@ -225,6 +247,7 @@ impl IntoResponseParts for HxResponseTriggerAfterSettle {
.unwrap_or_default(),
)?,
);
+
Ok(res)
}
}
@@ -233,7 +256,8 @@ impl IntoResponseParts for HxResponseTriggerAfterSettle {
///
/// Allows you to trigger client-side events after the swap step.
///
-/// Will fail if the supplied events contain or produce characters that are not visible ASCII (32-127) when serializing to json.
+/// Will fail if the supplied events contain or produce characters that are not
+/// visible ASCII (32-127) when serializing to json.
#[derive(Debug, Clone)]
pub struct HxResponseTriggerAfterSwap(pub Vec);
@@ -250,6 +274,7 @@ impl IntoResponseParts for HxResponseTriggerAfterSwap {
.unwrap_or_default(),
)?,
);
+
Ok(res)
}
}
@@ -272,7 +297,8 @@ pub enum SwapOption {
AfterEnd,
/// Deletes the target element regardless of the response
Delete,
- /// Does not append content from response (out of band items will still be processed).
+ /// Does not append content from response (out of band items will still be
+ /// processed).
None,
}
diff --git a/src/responders/serde.rs b/src/responders/serde.rs
index 8d71ed7..c65aa10 100644
--- a/src/responders/serde.rs
+++ b/src/responders/serde.rs
@@ -18,26 +18,30 @@ use crate::{
/// The `HX-Location` header.
///
-/// This response header can be used to trigger a client side redirection without reloading the whole page. Instead of changing the page’s location it will act like following a hx-boost link, creating a new history entry, issuing an ajax request to the value of the header and pushing the path into history.
+/// This response header can be used to trigger a client side redirection
+/// without reloading the whole page.
///
-/// Will fail if the supplied data contains or produces characters that are not visible ASCII (32-127) when serializing to json.
+/// Will fail if the supplied data contains or produces characters that are not
+/// visible ASCII (32-127) when serializing to JSON.
+///
+/// See for more information.
#[derive(Debug, Clone, Serialize)]
pub struct HxLocation {
- /// Url to load the response from
+ /// Url to load the response from.
pub path: String,
- /// The source element of the request
+ /// The source element of the request.
pub source: Option,
- /// An event that "triggered" the request
+ /// An event that "triggered" the request.
pub event: Option,
- /// A callback that will handle the response HTML
+ /// A callback that will handle the response HTML.
pub handler: Option,
- /// The target to swap the response into
+ /// The target to swap the response into.
pub target: Option,
- /// How the response will be swapped in relative to the target
+ /// How the response will be swapped in relative to the target.
pub swap: Option,
- /// Values to submit with the request
+ /// Values to submit with the request.
pub values: Option,
- /// headers to submit with the request
+ /// Headers to submit with the request.
pub headers: Option,
}
@@ -74,6 +78,7 @@ impl IntoResponseParts for HxLocation {
};
res.headers_mut().insert(headers::HX_LOCATION, header_value);
+
Ok(res)
}
}
@@ -82,7 +87,8 @@ impl IntoResponseParts for HxLocation {
///
/// Allows you to trigger client-side events.
///
-/// Will fail if the supplied events contain or produce characters that are not visible ASCII (32-127) when serializing to json.
+/// Will fail if the supplied events contain or produce characters that are not
+/// visible ASCII (32-127) when serializing to json.
#[derive(Debug, Clone)]
pub struct HxTrigger(pub Vec);
@@ -92,6 +98,7 @@ impl IntoResponseParts for HxTrigger {
fn into_response_parts(self, mut res: ResponseParts) -> Result {
res.headers_mut()
.insert(headers::HX_TRIGGER, events_to_header_value(self.0)?);
+
Ok(res)
}
}
@@ -100,7 +107,8 @@ impl IntoResponseParts for HxTrigger {
///
/// Allows you to trigger client-side events after the settle step.
///
-/// Will fail if the supplied events contain or produce characters that are not visible ASCII (32-127) when serializing to json.
+/// Will fail if the supplied events contain or produce characters that are not
+/// visible ASCII (32-127) when serializing to json.
#[derive(Debug, Clone)]
pub struct HxTriggerAfterSettle(Vec);
@@ -112,6 +120,7 @@ impl IntoResponseParts for HxTriggerAfterSettle {
headers::HX_TRIGGER_AFTER_SETTLE,
events_to_header_value(self.0)?,
);
+
Ok(res)
}
}
@@ -120,7 +129,8 @@ impl IntoResponseParts for HxTriggerAfterSettle {
///
/// Allows you to trigger client-side events after the swap step.
///
-/// Will fail if the supplied events contain or produce characters that are not visible ASCII (32-127) when serializing to json.
+/// Will fail if the supplied events contain or produce characters that are not
+/// visible ASCII (32-127) when serializing to json.
#[derive(Debug, Clone)]
pub struct HxTriggerAfterSwap(Vec);
@@ -132,6 +142,7 @@ impl IntoResponseParts for HxTriggerAfterSwap {
headers::HX_TRIGGER_AFTER_SWAP,
events_to_header_value(self.0)?,
);
+
Ok(res)
}
}
@@ -160,15 +171,16 @@ pub(crate) fn events_to_header_value(events: Vec) -> Result>();
serde_json::to_string(&header_value)?
} else {
- // no event contains data, the event names can be put in the header value separated
- // by a comma.
+ // no event contains data, the event names can be put in the header
+ // value separated by a comma.
events
.into_iter()
.map(|e| e.name)
@@ -179,8 +191,8 @@ pub(crate) fn events_to_header_value(events: Vec) -> Result(&self, serializer: S) -> Result
where