fix issue 1586 (#2725)
This commit is contained in:
1 parent
e73484795a
commit
3db24934d6
2 files changed
+17
No files matched your search
@@ -71,3 +71,19 @@ pub enum FmtSegment {
|
|||||||
id: usize,
|
id: usize,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A helper function for deserializing to a `&'static str`.
|
||||||
|
/// Parses escaped characters (like `"\n"` or `"\t"`),
|
||||||
|
/// which cannot be done in-place using the default serde json deserializer.
|
||||||
|
///
|
||||||
|
/// **Leaks the memory** in order to achieve a `'static` reference.
|
||||||
|
///
|
||||||
|
/// Solves [this issue](https://github.com/DioxusLabs/dioxus/issues/1586).
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub fn static_str_deserializer<'de, D>(deserializer: D) -> Result<&'static str, D::Error>
|
||||||
|
where
|
||||||
|
D: serde::de::Deserializer<'de>,
|
||||||
|
{
|
||||||
|
<String as serde::Deserialize>::deserialize(deserializer)
|
||||||
|
.map(|s| Box::leak(Box::new(s)) as &'static str)
|
||||||
|
}
|
||||||
@@ -523,6 +523,7 @@ pub enum TemplateNode {
|
|||||||
/// This template node is just a piece of static text
|
/// This template node is just a piece of static text
|
||||||
Text {
|
Text {
|
||||||
/// The actual text
|
/// The actual text
|
||||||
|
#[serde(deserialize_with = "crate::hotreload_utils::static_str_deserializer")]
|
||||||
text: &'static str,
|
text: &'static str,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user