Skip to content

Commit 0f2fa77

Browse files
committed
Add (nightly) no_std support
1 parent f82f037 commit 0f2fa77

File tree

8 files changed

+35
-7
lines changed

8 files changed

+35
-7
lines changed

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ circle-ci = { repository = "vislyhq/stretch", branch = "master" }
1616
maintenance = { status = "experimental" }
1717

1818
[dependencies]
19-
ref_eq = "1.0.0"
19+
libm = "0.1.2"
20+
21+
[features]
22+
default = ["std"]
23+
std = []
2024

2125
[dev-dependencies]
2226
criterion = "0.2"

src/algo.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
use ref_eq::ref_eq;
2-
use std::f32;
1+
#[cfg(not(feature = "std"))]
2+
use alloc::{vec, vec::Vec};
3+
#[cfg(not(feature = "std"))]
4+
use libm::F32Ext;
5+
6+
use core::f32;
37

48
use crate::layout;
9+
use crate::ref_eq::ref_eq;
510

611
use crate::style;
712
use crate::style::*;

src/geometry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::ops::Add;
1+
use core::ops::Add;
22

33
use crate::number::Number;
44
use crate::style;

src/layout.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#[cfg(not(feature = "std"))]
2+
use alloc::vec::Vec;
3+
14
use crate::geometry::{Point, Size};
25

36
#[derive(Debug, Clone)]

src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
#![cfg_attr(not(feature = "std"), no_std)]
2+
#![cfg_attr(not(feature = "std"), feature(alloc))]
3+
#[cfg(not(feature = "std"))]
4+
extern crate alloc;
5+
16
pub mod geometry;
27
pub mod layout;
38
pub mod number;
49
pub mod style;
510

611
mod algo;
12+
mod ref_eq;
713
pub use crate::algo::compute;

src/number.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::ops;
1+
use core::ops;
22

33
#[derive(Copy, Clone, PartialEq, Debug)]
44
pub enum Number {

src/ref_eq.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// Determine if two borrowed pointers point to the same thing.<Paste>
2+
#[inline]
3+
pub fn ref_eq<'a, 'b, T>(thing: &'a T, other: &'b T) -> bool {
4+
(thing as *const T) == (other as *const T)
5+
}

src/style.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#[cfg(not(feature = "std"))]
2+
use alloc::boxed::Box;
3+
#[cfg(not(feature = "std"))]
4+
use alloc::{vec, vec::Vec};
5+
16
use crate::algo;
27
use crate::geometry::{Rect, Size};
38
use crate::number::Number;
@@ -246,7 +251,7 @@ pub struct Node {
246251

247252
pub children: Vec<Node>,
248253

249-
pub layout_cache: std::cell::RefCell<Option<LayoutCache>>,
254+
pub layout_cache: core::cell::RefCell<Option<LayoutCache>>,
250255
}
251256

252257
impl Default for Node {
@@ -285,7 +290,7 @@ impl Default for Node {
285290

286291
children: vec![],
287292

288-
layout_cache: std::cell::RefCell::new(None),
293+
layout_cache: core::cell::RefCell::new(None),
289294
}
290295
}
291296
}

0 commit comments

Comments
 (0)