Use the new nonzero crate in the msg crate

This commit is contained in:
Simon Sapin 2017-10-12 00:28:50 +02:00
parent c4bf3ec14f
commit 57709dc0bf
8 changed files with 43 additions and 17 deletions

View file

@ -9,9 +9,13 @@ publish = false
name = "msg"
path = "lib.rs"
[features]
unstable = ["nonzero/unstable"]
[dependencies]
bitflags = "0.7"
heapsize = "0.4"
heapsize_derive = "0.1"
serde = { version = "1.0.14", features = [ "unstable" ] }
nonzero = {path = "../nonzero"}
serde = "1.0.14"
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}

View file

@ -5,7 +5,7 @@
//! The high-level interface from script to constellation. Using this abstract interface helps
//! reduce coupling between these two components.
use core::nonzero::NonZero;
use nonzero::NonZeroU32;
use std::cell::Cell;
use std::fmt;
use webrender_api;
@ -195,9 +195,9 @@ impl PipelineNamespace {
});
}
fn next_index(&mut self) -> NonZero<u32> {
fn next_index(&mut self) -> NonZeroU32 {
self.index += 1;
NonZero::new(self.index).expect("pipeline id index wrapped!")
NonZeroU32::new(self.index).expect("pipeline id index wrapped!")
}
fn next_pipeline_id(&mut self) -> PipelineId {
@ -221,7 +221,7 @@ thread_local!(pub static PIPELINE_NAMESPACE: Cell<Option<PipelineNamespace>> = C
pub struct PipelineNamespaceId(pub u32);
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
pub struct PipelineIndex(pub NonZero<u32>);
pub struct PipelineIndex(pub NonZeroU32);
known_heap_size!(0, PipelineIndex);
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, HeapSizeOf, Ord, PartialEq, PartialOrd, Serialize)]
@ -264,7 +264,7 @@ impl fmt::Display for PipelineId {
}
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
pub struct BrowsingContextIndex(pub NonZero<u32>);
pub struct BrowsingContextIndex(pub NonZeroU32);
known_heap_size!(0, BrowsingContextIndex);
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, HeapSizeOf, Ord, PartialEq, PartialOrd, Serialize)]
@ -339,11 +339,15 @@ impl PartialEq<BrowsingContextId> for TopLevelBrowsingContextId {
// We provide ids just for unit testing.
pub const TEST_NAMESPACE: PipelineNamespaceId = PipelineNamespaceId(1234);
#[allow(unsafe_code)]
pub const TEST_PIPELINE_INDEX: PipelineIndex = unsafe { PipelineIndex(NonZero::new_unchecked(5678)) };
#[cfg(feature = "unstable")]
pub const TEST_PIPELINE_INDEX: PipelineIndex = unsafe { PipelineIndex(NonZeroU32::new_unchecked(5678)) };
#[cfg(feature = "unstable")]
pub const TEST_PIPELINE_ID: PipelineId = PipelineId { namespace_id: TEST_NAMESPACE, index: TEST_PIPELINE_INDEX };
#[allow(unsafe_code)]
#[cfg(feature = "unstable")]
pub const TEST_BROWSING_CONTEXT_INDEX: BrowsingContextIndex =
unsafe { BrowsingContextIndex(NonZero::new_unchecked(8765)) };
unsafe { BrowsingContextIndex(NonZeroU32::new_unchecked(8765)) };
#[cfg(feature = "unstable")]
pub const TEST_BROWSING_CONTEXT_ID: BrowsingContextId =
BrowsingContextId { namespace_id: TEST_NAMESPACE, index: TEST_BROWSING_CONTEXT_INDEX };

View file

@ -2,16 +2,16 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#![feature(const_fn)]
#![feature(const_nonzero_new)]
#![feature(nonzero)]
#![cfg_attr(feature = "unstable", feature(nonzero))]
#![cfg_attr(feature = "unstable", feature(const_fn))]
#![cfg_attr(feature = "unstable", feature(const_nonzero_new))]
#![deny(unsafe_code)]
#[macro_use]
extern crate bitflags;
extern crate core;
#[macro_use] extern crate heapsize;
#[macro_use] extern crate heapsize_derive;
extern crate nonzero;
#[macro_use] extern crate serde;
extern crate webrender_api;