pub struct HxLocation {
pub path: String,
pub options: LocationOptions,
}Expand description
Performs a client-side redirect that does not trigger a full page reload,
via the HX-Location header.
In its simplest form it carries just a path. Set any of the LocationOptions
fields, through the builder methods, to control how htmx fetches and swaps
the new content; when any option is set, the header is serialized as JSON.
§Examples
use topcoat::htmx::{HxLocation, SwapOption};
// Plain path: `HX-Location: /home`
let simple = HxLocation::new("/home");
// With options, serialized as JSON.
let detailed = HxLocation::new("/home")
.target("#main")
.swap(SwapOption::InnerHtml);Fields§
§path: StringThe path (URL) to fetch the new content from.
options: LocationOptionsOptional context controlling the fetch and swap.
Implementations§
Source§impl HxLocation
impl HxLocation
Sourcepub fn new(path: impl Into<String>) -> Self
pub fn new(path: impl Into<String>) -> Self
Creates a location targeting path with no extra options.
Sourcepub fn source(self, source: impl Into<String>) -> Self
pub fn source(self, source: impl Into<String>) -> Self
Sets the source element for the request (source).
Sourcepub fn event(self, event: impl Into<String>) -> Self
pub fn event(self, event: impl Into<String>) -> Self
Sets the event that triggered the request (event).
Sourcepub fn handler(self, handler: impl Into<String>) -> Self
pub fn handler(self, handler: impl Into<String>) -> Self
Sets a callback that handles the response (handler).
Sourcepub fn target(self, target: impl Into<String>) -> Self
pub fn target(self, target: impl Into<String>) -> Self
Sets the element to swap the response into (target), a CSS selector.
Sourcepub fn swap(self, swap: SwapOption) -> Self
pub fn swap(self, swap: SwapOption) -> Self
Sets how the response is swapped in (swap).
Trait Implementations§
Source§impl Clone for HxLocation
impl Clone for HxLocation
Source§fn clone(&self) -> HxLocation
fn clone(&self) -> HxLocation
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for HxLocation
impl Debug for HxLocation
impl Eq for HxLocation
Source§impl From<&str> for HxLocation
impl From<&str> for HxLocation
Source§impl From<String> for HxLocation
impl From<String> for HxLocation
Source§impl IntoResponseParts for HxLocation
impl IntoResponseParts for HxLocation
Source§impl PartialEq for HxLocation
impl PartialEq for HxLocation
impl StructuralPartialEq for HxLocation
Auto Trait Implementations§
impl Freeze for HxLocation
impl RefUnwindSafe for HxLocation
impl Send for HxLocation
impl Sync for HxLocation
impl Unpin for HxLocation
impl UnsafeUnpin for HxLocation
impl UnwindSafe for HxLocation
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> CloneAny for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.