Skip to content

Commit

Permalink
API tweaks for Taffy calc() integration (#104)
Browse files Browse the repository at this point in the history
* Make OpaqueElement wrap u64

Signed-off-by: Nico Burns <[email protected]>

* Make calc methods pub

Signed-off-by: Nico Burns <[email protected]>

---------

Signed-off-by: Nico Burns <[email protected]>
  • Loading branch information
nicoburns authored Jan 7, 2025
1 parent 098f1be commit 95ee4c3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions selectors/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ impl OpaqueElement {
}
}

/// Creates a new OpaqueElement from a type-erased non-null pointer
pub fn from_non_null_ptr(ptr: NonNull<()>) -> Self {
Self(ptr)
}

/// Returns a const ptr to the contained reference.
pub unsafe fn as_const_ptr<T>(&self) -> *const T {
self.0.as_ptr() as *const T
Expand Down
9 changes: 7 additions & 2 deletions style/values/computed/length_percentage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,12 @@ impl ToResolvedValue for LengthPercentage {

/// An unpacked `<length-percentage>` that borrows the `calc()` variant.
#[derive(Clone, Debug, PartialEq, ToCss)]
enum Unpacked<'a> {
pub enum Unpacked<'a> {
/// A `calc()` value
Calc(&'a CalcLengthPercentage),
/// A length value
Length(Length),
/// A percentage value
Percentage(Percentage),
}

Expand Down Expand Up @@ -397,8 +400,10 @@ impl LengthPercentage {
}
}

/// Unpack the tagged pointer representation of a length-percentage into an enum
/// representation with separate tag and value.
#[inline]
fn unpack<'a>(&'a self) -> Unpacked<'a> {
pub fn unpack<'a>(&'a self) -> Unpacked<'a> {
unsafe {
match self.tag() {
Tag::Calc => Unpacked::Calc(&*self.calc_ptr()),
Expand Down

0 comments on commit 95ee4c3

Please sign in to comment.