reduce usage of unsafe
This commit is contained in:
1 parent
738f1b3ce0
commit
170a3669f7
3 files changed
+47
-39
No files matched your search
@@ -48,7 +48,20 @@ impl<'a> Mutations<'a> {
|
||||
|
||||
/// Push a new mutation into the dom_edits list
|
||||
pub(crate) fn push(&mut self, mutation: Mutation<'static>) {
|
||||
unsafe { self.edits.push(std::mem::transmute(mutation)) }
|
||||
self.edits.push(mutation.downcast_lifetime())
|
||||
}
|
||||
}
|
||||
|
||||
impl Mutations<'static> {
|
||||
pub(crate) fn take<'a>(&mut self) -> Mutations<'a> {
|
||||
Mutations::<'a> {
|
||||
subtree: self.subtree,
|
||||
dirty_scopes: self.dirty_scopes.drain().collect(),
|
||||
templates: self.templates.split_off(0),
|
||||
// Safety: this downcasts the lifetime from 'static to 'a
|
||||
// This is safe because 'static outlives 'a
|
||||
edits: unsafe { std::mem::transmute(self.edits.split_off(0)) },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,3 +257,9 @@ pub enum Mutation<'a> {
|
||||
id: ElementId,
|
||||
},
|
||||
}
|
||||
|
||||
impl Mutation<'static> {
|
||||
pub(crate) fn downcast_lifetime<'a>(self) -> Mutation<'a> {
|
||||
unsafe { std::mem::transmute(self) }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user