fix issue 1586 followup (#2733)

This commit is contained in:
Adam Kundrát 2024-07-29 22:00:59 +02:00 committed by GitHub
parent b7127ad6ae
commit a1dfc4b4f0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 1 additions and 17 deletions

View file

@ -71,19 +71,3 @@ pub enum FmtSegment {
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)
}

View file

@ -523,7 +523,7 @@ pub enum TemplateNode {
/// This template node is just a piece of static text
Text {
/// The actual text
#[serde(deserialize_with = "crate::hotreload_utils::static_str_deserializer")]
#[serde(deserialize_with = "deserialize_string_leaky")]
text: &'static str,
},