datastar 0.3.1

Datastar SDK for Rust
Documentation
//! Datastar constants
#![allow(rustdoc::invalid_html_tags)]

// This is auto-generated by Datastar. DO NOT EDIT.

#[expect(unused)]
pub(crate) const DATASTAR_KEY: &str = "datastar";
#[allow(unused)]
pub(crate) const DATASTAR_REQ_HEADER_STR: &str = "datastar-request";
#[expect(unused)]
pub(crate) const VERSION: &str = "1.0.0-RC.1";

// #region Defaults

// #region Default durations

/// The default duration for retrying SSE on connection reset. This is part of the underlying retry mechanism of SSE.
pub const DEFAULT_SSE_RETRY_DURATION: u64 = 1000;

// #endregion

// #region Default strings

// #endregion

// #region Datalines

pub(crate) const SELECTOR_DATALINE_LITERAL: &str = "selector";
pub(crate) const MODE_DATALINE_LITERAL: &str = "mode";
pub(crate) const ELEMENTS_DATALINE_LITERAL: &str = "elements";
pub(crate) const USE_VIEW_TRANSITION_DATALINE_LITERAL: &str = "useViewTransition";
pub(crate) const SIGNALS_DATALINE_LITERAL: &str = "signals";
pub(crate) const ONLY_IF_MISSING_DATALINE_LITERAL: &str = "onlyIfMissing";

// #endregion

// #region Default booleans

/// Should elements be patched using the ViewTransition API?
pub(crate) const DEFAULT_ELEMENTS_USE_VIEW_TRANSITIONS: bool = false;
/// Should a given set of signals patch if they are missing?
pub(crate) const DEFAULT_PATCH_SIGNALS_ONLY_IF_MISSING: bool = false;

// #endregion

// #region Enums

/// The mode in which an element is patched into the DOM.
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ElementPatchMode {
    /// Morphs the element into the existing element.
    #[default]
    Outer,
    /// Replaces the inner HTML of the existing element.
    Inner,
    /// Removes the existing element.
    Remove,
    /// Replaces the existing element with the new element.
    Replace,
    /// Prepends the element inside to the existing element.
    Prepend,
    /// Appends the element inside the existing element.
    Append,
    /// Inserts the element before the existing element.
    Before,
    /// Inserts the element after the existing element.
    After,
}

impl ElementPatchMode {
    /// Returns the [`ElementPatchMode`] as a string.
    pub(crate) const fn as_str(&self) -> &str {
        match self {
            Self::Outer => "outer",
            Self::Inner => "inner",
            Self::Remove => "remove",
            Self::Replace => "replace",
            Self::Prepend => "prepend",
            Self::Append => "append",
            Self::Before => "before",
            Self::After => "after",
        }
    }
}
/// The type protocol on top of SSE which allows for core pushed based communication between the server and the client.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum EventType {
    /// An event for patching HTML elements into the DOM.
    PatchElements,
    /// An event for patching signals.
    PatchSignals,
}

impl EventType {
    /// Returns the [`EventType`] as a string.
    pub(crate) const fn as_str(&self) -> &str {
        match self {
            Self::PatchElements => "datastar-patch-elements",
            Self::PatchSignals => "datastar-patch-signals",
        }
    }
}
// #endregion

// #endregion