Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reinstate 1.65 MSRV #781

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ jobs:
# We only run `cargo build` (not `cargo test`) so as to avoid requiring dev-dependencies to build with the MSRV
# version. Building is likely sufficient as runtime errors varying between rust versions is very unlikely.
build-features-msrv:
name: "MSRV Build [Rust 1.83]"
name: "MSRV Build [Rust 1.65]"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.83
toolchain: 1.65
- run: cargo build

build-features-debug:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = [
"Nico Burns <[email protected]>",
]
edition = "2021"
rust-version = "1.83"
rust-version = "1.65"
include = ["src/**/*", "examples/**/*", "Cargo.toml", "README.md"]
description = "A flexible UI layout library "
repository = "https://github.com/DioxusLabs/taffy"
Expand Down
34 changes: 27 additions & 7 deletions src/style/dimension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@ use crate::style_helpers::{
FromFr, FromLength, FromPercent, TaffyAuto, TaffyFitContent, TaffyMaxContent, TaffyMinContent, TaffyZero,
};

// Note: these two functions are copied directly from the std (core) library. But by duplicating them
// here we can reduce MSRV from 1.83 all the way down to 1.65 while retaining const constructors.

/// Raw transmutation from `f32` to `u32`.
const fn to_bits(val: f32) -> u32 {
// SAFETY: `u32` is a plain old datatype so we can always transmute to it.
#[allow(unsafe_code)]
unsafe {
core::mem::transmute(val)
}
}
/// Raw transmutation from `u32` to `f32`.
const fn from_bits(v: u32) -> f32 {
// SAFETY: `u32` is a plain old datatype so we can always transmute from it.
#[allow(unsafe_code)]
unsafe {
core::mem::transmute(v)
}
}

/// A representation of a length as a compact 64-bit tagged pointer
#[derive(Copy, Clone, PartialEq, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
Expand Down Expand Up @@ -46,15 +66,15 @@ impl CompactLength {
/// to in their application (pixels, logical pixels, mm, etc) as they see fit.
#[inline(always)]
pub const fn length(val: f32) -> Self {
Self(((val.to_bits() as u64) << 32) | Self::LENGTH_TAG)
Self(((to_bits(val) as u64) << 32) | Self::LENGTH_TAG)
}

/// A percentage length relative to the size of the containing block.
///
/// **NOTE: percentages are represented as a f32 value in the range [0.0, 1.0] NOT the range [0.0, 100.0]**
#[inline(always)]
pub const fn percent(val: f32) -> Self {
Self(((val.to_bits() as u64) << 32) | Self::PERCENT_TAG)
Self(((to_bits(val) as u64) << 32) | Self::PERCENT_TAG)
}

/// A `calc()` value. The value passed here is treated as an opaque handle to
Expand All @@ -80,7 +100,7 @@ impl CompactLength {
/// Spec: <https://www.w3.org/TR/css3-grid-layout/#fr-unit>
#[inline(always)]
pub const fn fr(val: f32) -> Self {
Self(((val.to_bits() as u64) << 32) | Self::FR_TAG)
Self(((to_bits(val) as u64) << 32) | Self::FR_TAG)
}

/// The size should be the "min-content" size.
Expand Down Expand Up @@ -108,7 +128,7 @@ impl CompactLength {
/// by the min-content and max-content sizes.
#[inline(always)]
pub const fn fit_content_px(limit: f32) -> Self {
Self(((limit.to_bits() as u64) << 32) | Self::FIT_CONTENT_PX_TAG)
Self(((to_bits(limit) as u64) << 32) | Self::FIT_CONTENT_PX_TAG)
}

/// The size should be computed according to the "fit content" formula:
Expand All @@ -122,7 +142,7 @@ impl CompactLength {
/// by the min-content and max-content sizes.
#[inline(always)]
pub const fn fit_content_percent(limit: f32) -> Self {
Self(((limit.to_bits() as u64) << 32) | Self::FIT_CONTENT_PERCENT_TAG)
Self(((to_bits(limit) as u64) << 32) | Self::FIT_CONTENT_PERCENT_TAG)
}

/// Get the primary tag
Expand All @@ -135,7 +155,7 @@ impl CompactLength {
/// (e.g. the pixel value for a LENGTH variant)
#[inline(always)]
pub const fn value(self) -> f32 {
f32::from_bits((self.0 >> 32) as u32)
from_bits((self.0 >> 32) as u32)
}

/// Get the numeric value associated with the `CompactLength`
Expand All @@ -154,7 +174,7 @@ impl CompactLength {
/// Returns true if the value is 0 px
#[inline(always)]
pub const fn is_zero(self) -> bool {
matches!(self, Self::ZERO)
self.0 == Self::ZERO.0
}

/// Returns true if the value is a length or percentage value
Expand Down
Loading