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

Add (nightly) no_std support #11

Merged
merged 1 commit into from
Jan 16, 2019
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
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ circle-ci = { repository = "vislyhq/stretch", branch = "master" }
maintenance = { status = "experimental" }

[dependencies]
ref_eq = "1.0.0"
libm = "0.1.2"

[features]
default = ["std"]
std = []

[dev-dependencies]
criterion = "0.2"
Expand Down
9 changes: 7 additions & 2 deletions src/algo.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
use ref_eq::ref_eq;
use std::f32;
#[cfg(not(feature = "std"))]
use alloc::{vec, vec::Vec};
#[cfg(not(feature = "std"))]
use libm::F32Ext;

use core::f32;

use crate::layout;
use crate::ref_eq::ref_eq;

use crate::style;
use crate::style::*;
Expand Down
2 changes: 1 addition & 1 deletion src/geometry.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::ops::Add;
use core::ops::Add;

use crate::number::Number;
use crate::style;
Expand Down
3 changes: 3 additions & 0 deletions src/layout.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;

use crate::geometry::{Point, Size};

#[derive(Debug, Clone)]
Expand Down
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), feature(alloc))]
#[cfg(not(feature = "std"))]
extern crate alloc;

pub mod geometry;
pub mod layout;
pub mod number;
pub mod style;

mod algo;
mod ref_eq;
pub use crate::algo::compute;
2 changes: 1 addition & 1 deletion src/number.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::ops;
use core::ops;

#[derive(Copy, Clone, PartialEq, Debug)]
pub enum Number {
Expand Down
5 changes: 5 additions & 0 deletions src/ref_eq.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// Determine if two borrowed pointers point to the same thing.
#[inline]
pub fn ref_eq<'a, 'b, T>(thing: &'a T, other: &'b T) -> bool {
(thing as *const T) == (other as *const T)
}
9 changes: 7 additions & 2 deletions src/style.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#[cfg(not(feature = "std"))]
use alloc::boxed::Box;
#[cfg(not(feature = "std"))]
use alloc::{vec, vec::Vec};

use crate::algo;
use crate::geometry::{Rect, Size};
use crate::number::Number;
Expand Down Expand Up @@ -246,7 +251,7 @@ pub struct Node {

pub children: Vec<Node>,

pub layout_cache: std::cell::RefCell<Option<LayoutCache>>,
pub layout_cache: core::cell::RefCell<Option<LayoutCache>>,
}

impl Default for Node {
Expand Down Expand Up @@ -285,7 +290,7 @@ impl Default for Node {

children: vec![],

layout_cache: std::cell::RefCell::new(None),
layout_cache: core::cell::RefCell::new(None),
}
}
}
Expand Down