Don't use Lazy to initialize the ITEM_TREE, use OnceBox instead

Lazy needs std
This commit is contained in:
Olivier Goffart 2021-12-01 09:51:58 +01:00 committed by Olivier Goffart
parent 6b60e832ed
commit a201c31eaf
3 changed files with 7 additions and 7 deletions

View file

@ -20,7 +20,7 @@ default = ["backend-gl", "x11", "backend-qt"]
std = ["sixtyfps-corelib/std"] std = ["sixtyfps-corelib/std"]
[dependencies] [dependencies]
once_cell = { version = "1.5", default-features = false } once_cell = { version = "1.5", default-features = false, features = ["alloc"] }
sixtyfps-macros = { version = "=0.1.6", path = "sixtyfps-macros" } sixtyfps-macros = { version = "=0.1.6", path = "sixtyfps-macros" }
const-field-offset = { version = "0.1.2", path = "../../helper_crates/const-field-offset" } const-field-offset = { version = "0.1.2", path = "../../helper_crates/const-field-offset" }
vtable = { version = "0.1.4", path = "../../helper_crates/vtable" } vtable = { version = "0.1.4", path = "../../helper_crates/vtable" }

View file

@ -251,8 +251,7 @@ pub fn register_font_from_path<P: AsRef<std::path::Path>>(
pub mod re_exports { pub mod re_exports {
pub use const_field_offset::{self, FieldOffsets, PinnedDrop}; pub use const_field_offset::{self, FieldOffsets, PinnedDrop};
pub use core::iter::FromIterator; pub use core::iter::FromIterator;
#[cfg(feature = "std")] pub use once_cell::race::OnceBox;
pub use once_cell::sync::Lazy;
pub use once_cell::unsync::OnceCell; pub use once_cell::unsync::OnceCell;
pub use pin_weak::rc::PinWeak; pub use pin_weak::rc::PinWeak;
pub use sixtyfps_corelib::animations::EasingCurve; pub use sixtyfps_corelib::animations::EasingCurve;

View file

@ -995,10 +995,11 @@ fn generate_component(
fn item_tree() -> &'static [sixtyfps::re_exports::ItemTreeNode<Self>] { fn item_tree() -> &'static [sixtyfps::re_exports::ItemTreeNode<Self>] {
use sixtyfps::re_exports::*; use sixtyfps::re_exports::*;
ComponentVTable_static!(static VT for #inner_component_id); ComponentVTable_static!(static VT for #inner_component_id);
// FIXME: ideally this should be a const // FIXME: ideally this should be a const, but we can't because of the pointer to the vtable
static ITEM_TREE : Lazy<[sixtyfps::re_exports::ItemTreeNode<#inner_component_id>; #item_tree_array_len]> = static ITEM_TREE : sixtyfps::re_exports::OnceBox<
Lazy::new(|| [#(#item_tree_array),*]); [sixtyfps::re_exports::ItemTreeNode<#inner_component_id>; #item_tree_array_len]
&*ITEM_TREE > = sixtyfps::re_exports::OnceBox::new();
&*ITEM_TREE.get_or_init(|| Box::new([#(#item_tree_array),*]))
} }
}), }),
Some(quote! { Some(quote! {