pub struct HmrMessage {
pub kind: HmrType,
pub paths: Vec<String>,
pub sha: String,
}Expand description
A single HMR frame.
Fields§
§kind: HmrTypeFrame type.
paths: Vec<String>Paths affected. For hmr-html these are page URLs; for
hmr-css these are asset URLs; for reload this may be empty.
sha: StringShort content hash. Optional — empty string is fine.
Implementations§
Source§impl HmrMessage
impl HmrMessage
Sourcepub const fn css(paths: Vec<String>) -> Self
pub const fn css(paths: Vec<String>) -> Self
Build a CSS-swap frame for one or more stylesheet paths.
§Examples
use ssg::hmr::{HmrMessage, HmrType};
let m = HmrMessage::css(vec!["x.css".into()]);
assert_eq!(m.kind, HmrType::HmrCss);
assert_eq!(m.paths, vec!["x.css"]);Sourcepub const fn html(paths: Vec<String>) -> Self
pub const fn html(paths: Vec<String>) -> Self
Build an HTML-partial frame for one or more page URLs.
§Examples
use ssg::hmr::{HmrMessage, HmrType};
let m = HmrMessage::html(vec!["/a/".into()]);
assert_eq!(m.kind, HmrType::HmrHtml);Sourcepub const fn reload() -> Self
pub const fn reload() -> Self
Build a full-page-reload frame.
§Examples
use ssg::hmr::{HmrMessage, HmrType};
let m = HmrMessage::reload();
assert_eq!(m.kind, HmrType::Reload);
assert!(m.paths.is_empty());Sourcepub fn with_sha(self, sha: impl Into<String>) -> Self
pub fn with_sha(self, sha: impl Into<String>) -> Self
Attach a content hash for client-side de-duplication.
§Examples
use ssg::hmr::HmrMessage;
let m = HmrMessage::reload().with_sha("abc123");
assert_eq!(m.sha, "abc123");Sourcepub fn to_json(&self) -> String
pub fn to_json(&self) -> String
Serialise to the JSON wire format. Infallible — the struct is always serialisable.
§Panics
Only if serde_json cannot serialise a primitive Vec<String>,
which is impossible.
§Examples
use ssg::hmr::HmrMessage;
let m = HmrMessage::css(vec!["a.css".into()]);
let json = m.to_json();
assert!(json.contains("\"type\":\"hmr-css\""));Trait Implementations§
Source§impl Clone for HmrMessage
impl Clone for HmrMessage
Source§fn clone(&self) -> HmrMessage
fn clone(&self) -> HmrMessage
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 HmrMessage
impl Debug for HmrMessage
Source§impl<'de> Deserialize<'de> for HmrMessage
impl<'de> Deserialize<'de> for HmrMessage
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for HmrMessage
Source§impl PartialEq for HmrMessage
impl PartialEq for HmrMessage
Source§fn eq(&self, other: &HmrMessage) -> bool
fn eq(&self, other: &HmrMessage) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl Serialize for HmrMessage
impl Serialize for HmrMessage
impl StructuralPartialEq for HmrMessage
Auto Trait Implementations§
impl Freeze for HmrMessage
impl RefUnwindSafe for HmrMessage
impl Send for HmrMessage
impl Sync for HmrMessage
impl Unpin for HmrMessage
impl UnsafeUnpin for HmrMessage
impl UnwindSafe for HmrMessage
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more