Skip to content

Commit

Permalink
Make CacheMut an associated type
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburns committed Jul 16, 2024
1 parent 7fd3e48 commit dd3007c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/tree/taffy_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ where
FnMut(Size<Option<f32>>, Size<AvailableSpace>, NodeId, Option<&mut NodeContext>, &Style) -> Size<f32>,
{
type CoreContainerStyle<'a> = &'a Style where Self : 'a;
type CacheMut<'b> = &'b mut Cache where Self : 'b;

#[inline(always)]
fn get_core_container_style(&self, node_id: NodeId) -> Self::CoreContainerStyle<'_> {
Expand Down
9 changes: 8 additions & 1 deletion src/tree/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ use crate::style::{AvailableSpace, CoreStyle};
use crate::style::{FlexboxContainerStyle, FlexboxItemStyle};
#[cfg(feature = "grid")]
use crate::style::{GridContainerStyle, GridItemStyle};
use core::ops::{Deref, DerefMut};

/// This trait is Taffy's abstraction for downward tree traversal.
/// However, this trait does *not* require access to any node's other than a single container node's immediate children unless you also intend to implement `TraverseTree`.
Expand Down Expand Up @@ -167,14 +168,20 @@ pub trait LayoutPartialTree: TraversePartialTree {
where
Self: 'a;

/// A mutable reference to the cache. This is an associated type to allow for different
/// types of mutable reference such as mutex or refcell guards
type CacheMut<'b>: Deref<Target = Cache> + DerefMut
where
Self: 'b;

/// Get core style
fn get_core_container_style(&self, node_id: NodeId) -> Self::CoreContainerStyle<'_>;

/// Set the node's unrounded layout
fn set_unrounded_layout(&mut self, node_id: NodeId, layout: &Layout);

/// Get a mutable reference to the [`Cache`] for this node.
fn get_cache_mut(&mut self, node_id: NodeId) -> &mut Cache;
fn get_cache_mut(&mut self, node_id: NodeId) -> Self::CacheMut<'_>;

/// Compute the specified node's size or full layout given the specified constraints
fn compute_child_layout(&mut self, node_id: NodeId, inputs: LayoutInput) -> LayoutOutput;
Expand Down

0 comments on commit dd3007c

Please sign in to comment.