Skip to content
This repository has been archived by the owner on Dec 22, 2024. It is now read-only.

Commit

Permalink
fix: cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
ycysdf committed Mar 10, 2024
1 parent 296feb6 commit 24a76d2
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 5 deletions.
2 changes: 1 addition & 1 deletion crates/rxy_bevy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version = "0.1.0"
[dependencies]
#rxy_bevy_element.workspace = true
rxy_bevy_macro.workspace = true
rxy_core = { workspace = true, features = ["common_renderer", "async-channel", "bevy", "xy_reactive", "bevy_reflect"] }
rxy_core = { workspace = true, features = ["common_renderer", "async-channel", "bevy", "xy_reactive", "bevy_reflect", "x_iter_source"] }
xy_reactive = { workspace = true, optional = true, features = ["bevy"] }
rxy_macro.workspace = true
hooked_collection.workspace = true
Expand Down
1 change: 1 addition & 0 deletions crates/rxy_bevy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub mod prelude {

pub use crate::renderer::common_renderer::*;
pub use crate::renderer::BevyElement;
#[cfg(feature = "style")]
pub use crate::renderer::style::ElementViewStyleExt;

pub use super::all_attrs::{CommonAttrsElementViewBuilder, CommonAttrsViewBuilder};
Expand Down
1 change: 1 addition & 0 deletions crates/rxy_core/src/element/attr_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use alloc::borrow::Cow;
use alloc::string::String;
use core::fmt::Debug;
use core::ops::Deref;
use alloc::vec::Vec;

pub trait AttrValue: MaybeReflect + MaybeSend + MaybeSync + Debug + 'static {
fn clone_att_value(&self) -> SmallBox<dyn AttrValue, S1>;
Expand Down
2 changes: 1 addition & 1 deletion crates/rxy_core/src/impl/x_iter_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use core::future::Future;
use core::hash::{Hash, Hasher};
use core::marker::PhantomData;
use core::pin::pin;
use std::cmp::Ordering;
use core::cmp::Ordering;
use futures_lite::stream::Map;
use futures_lite::{FutureExt, StreamExt};
use hooked_collection::{
Expand Down
13 changes: 10 additions & 3 deletions crates/rxy_core/src/remove_on_drop.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
use crate::{NodeTree, Renderer, RendererWorld, ViewKey};
use bevy_utils::synccell::SyncCell;
use bevy_utils::OnDrop;
use crate::utils::SyncCell;
use crate::renderer::DeferredNodeTreeScoped;
use alloc::boxed::Box;
use crate::utils::OnDrop;

#[allow(dead_code)]
pub struct ViewRemoveOnDrop(SyncCell<OnDrop<Box<dyn FnOnce() + Send>>>);
#[cfg(feature = "send_sync")]
pub struct ViewRemoveOnDrop(
SyncCell<OnDrop<Box<dyn FnOnce() + crate::MaybeSend>>>
);
#[allow(dead_code)]
#[cfg(not(feature = "send_sync"))]
pub struct ViewRemoveOnDrop(SyncCell<OnDrop<Box<dyn FnOnce()>>>);

pub trait RemoveOnDropWorldExt<R>
where
Expand Down
5 changes: 5 additions & 0 deletions crates/rxy_core/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ pub use bevy_utils::all_tuples;
pub use bevy_utils::futures::now_or_never;
#[cfg(feature = "bevy")]
pub use bevy_utils::synccell::SyncCell;
#[cfg(feature = "bevy")]
pub use bevy_utils::OnDrop;

#[cfg(not(feature = "bevy"))]
pub use apis::now_or_never;
#[cfg(not(feature = "bevy"))]
pub use on_drop::OnDrop;
#[cfg(not(feature = "bevy"))]
pub use rxy_macro::{all_tuples, all_tuples_with_size};
#[cfg(not(feature = "bevy"))]
pub use synccell::SyncCell;
Expand All @@ -20,6 +24,7 @@ pub type AHasher = ahash::AHasher;

#[cfg(not(feature = "bevy"))]
mod synccell;
mod on_drop;

#[cfg(not(feature = "bevy"))]
mod apis {
Expand Down
22 changes: 22 additions & 0 deletions crates/rxy_core/src/utils/on_drop.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use core::mem::ManuallyDrop;

pub struct OnDrop<F: FnOnce()> {
callback: ManuallyDrop<F>,
}

impl<F: FnOnce()> OnDrop<F> {
/// Returns an object that will invoke the specified callback when dropped.
pub fn new(callback: F) -> Self {
Self {
callback: ManuallyDrop::new(callback),
}
}
}

impl<F: FnOnce()> Drop for OnDrop<F> {
fn drop(&mut self) {
// SAFETY: We may move out of `self`, since this instance can never be observed after it's dropped.
let callback = unsafe { ManuallyDrop::take(&mut self.callback) };
callback();
}
}

0 comments on commit 24a76d2

Please sign in to comment.