Remove components/nonzero, use std::num::NonZero instead

This commit is contained in:
Simon Sapin 2018-05-24 12:15:12 +02:00
parent d55a003c92
commit e39f741321
15 changed files with 5 additions and 158 deletions

11
Cargo.lock generated
View file

@ -296,7 +296,6 @@ dependencies = [
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"malloc_size_of 0.0.1",
"malloc_size_of_derive 0.0.1",
"nonzero 0.0.1",
"offscreen_gl_context 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_bytes 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -433,7 +432,6 @@ dependencies = [
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"msg 0.0.1",
"net_traits 0.0.1",
"nonzero 0.0.1",
"profile_traits 0.0.1",
"script_traits 0.0.1",
"servo_config 0.0.1",
@ -1840,7 +1838,6 @@ dependencies = [
"bitflags 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"malloc_size_of 0.0.1",
"malloc_size_of_derive 0.0.1",
"nonzero 0.0.1",
"serde 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)",
"size_of_test 0.0.1",
"webrender_api 0.57.2 (git+https://github.com/servo/webrender)",
@ -1951,13 +1948,6 @@ name = "nom"
version = "1.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "nonzero"
version = "0.0.1"
dependencies = [
"serde 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-integer"
version = "0.1.38"
@ -2862,7 +2852,6 @@ version = "0.0.1"
dependencies = [
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"nonzero 0.0.1",
]
[[package]]

View file

@ -17,7 +17,6 @@ gleam = "0.5.1"
lazy_static = "1"
malloc_size_of = { path = "../malloc_size_of" }
malloc_size_of_derive = { path = "../malloc_size_of_derive" }
nonzero = {path = "../nonzero"}
offscreen_gl_context = {version = "0.17", features = ["serde"]}
serde = "1.0"
serde_bytes = "0.10"

View file

@ -14,7 +14,6 @@ extern crate ipc_channel;
#[macro_use] extern crate lazy_static;
extern crate malloc_size_of;
#[macro_use] extern crate malloc_size_of_derive;
extern crate nonzero;
extern crate offscreen_gl_context;
#[macro_use] extern crate serde;
extern crate serde_bytes;

View file

@ -4,9 +4,9 @@
use euclid::Size2D;
use gleam::gl;
use nonzero::NonZeroU32;
use offscreen_gl_context::{GLContextAttributes, GLLimits};
use serde_bytes::ByteBuf;
use std::num::NonZeroU32;
use webrender_api::{DocumentId, ImageKey, PipelineId};
/// Sender type used in WebGLCommands.

View file

@ -24,7 +24,6 @@ libc = "0.2"
log = "0.4"
msg = {path = "../msg"}
net_traits = {path = "../net_traits"}
nonzero = {path = "../nonzero"}
profile_traits = {path = "../profile_traits"}
script_traits = {path = "../script_traits"}
servo_config = {path = "../config"}

View file

@ -18,7 +18,6 @@ use msg::constellation_msg::{PipelineId, PipelineIndex, PipelineNamespaceId};
use net_traits::image::base::Image;
#[cfg(feature = "gleam")]
use net_traits::image::base::PixelFormat;
use nonzero::NonZeroU32;
use profile_traits::time::{self, ProfilerCategory, profile};
use script_traits::{AnimationState, AnimationTickType, ConstellationMsg, LayoutControlMsg};
use script_traits::{MouseButton, MouseEventType, ScrollState, TouchEventType, TouchId};
@ -30,6 +29,7 @@ use std::collections::HashMap;
use std::env;
use std::fs::{File, create_dir_all};
use std::io::Write;
use std::num::NonZeroU32;
use std::rc::Rc;
use std::sync::mpsc::Sender;
use std::time::Instant;

View file

@ -17,7 +17,6 @@ extern crate libc;
extern crate log;
extern crate msg;
extern crate net_traits;
extern crate nonzero;
extern crate profile_traits;
extern crate script_traits;
extern crate servo_config;

View file

@ -11,15 +11,11 @@ path = "lib.rs"
test = false
doctest = false
[features]
unstable = ["nonzero/unstable"]
[dependencies]
bitflags = "1.0"
malloc_size_of = { path = "../malloc_size_of" }
malloc_size_of_derive = { path = "../malloc_size_of_derive" }
nonzero = {path = "../nonzero"}
serde = "1.0.14"
serde = "1.0.60"
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
[dev-dependencies]

View file

@ -5,9 +5,9 @@
//! The high-level interface from script to constellation. Using this abstract interface helps
//! reduce coupling between these two components.
use nonzero::NonZeroU32;
use std::cell::Cell;
use std::fmt;
use std::num::NonZeroU32;
use webrender_api;
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
@ -390,15 +390,11 @@ impl fmt::Display for HistoryStateId {
// We provide ids just for unit testing.
pub const TEST_NAMESPACE: PipelineNamespaceId = PipelineNamespaceId(1234);
#[allow(unsafe_code)]
#[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(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

@ -8,7 +8,6 @@
extern crate bitflags;
#[macro_use] extern crate malloc_size_of;
#[macro_use] extern crate malloc_size_of_derive;
extern crate nonzero;
#[macro_use] extern crate serde;
extern crate webrender_api;

View file

@ -1,15 +0,0 @@
[package]
name = "nonzero"
version = "0.0.1"
authors = ["The Servo Project Developers"]
license = "MPL-2.0"
publish = false
[lib]
path = "lib.rs"
[features]
unstable = []
[dependencies]
serde = "1.0.14"

View file

@ -1,111 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */
//! `NonZero*` types that are either `core::nonzero::NonZero<_>`
//! or some stable types with an equivalent API (but no memory layout optimization).
#![cfg_attr(feature = "unstable", feature(const_fn))]
extern crate serde;
use std::fmt;
macro_rules! impl_nonzero_fmt {
( ( $( $Trait: ident ),+ ) for $Ty: ident ) => {
$(
impl fmt::$Trait for $Ty {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.get().fmt(f)
}
}
)+
}
}
macro_rules! nonzero_integers {
( $( $Ty: ident($Int: ty); )+ ) => {
$(
#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct $Ty(
#[cfg(feature = "unstable")] std::num::$Ty,
#[cfg(not(feature = "unstable"))] $Int,
);
impl $Ty {
#[cfg(feature = "unstable")]
#[inline]
pub const unsafe fn new_unchecked(n: $Int) -> Self {
$Ty(std::num::$Ty::new_unchecked(n))
}
#[cfg(not(feature = "unstable"))]
#[inline]
pub unsafe fn new_unchecked(n: $Int) -> Self {
$Ty(n)
}
#[cfg(feature = "unstable")]
#[inline]
pub fn new(n: $Int) -> Option<Self> {
std::num::$Ty::new(n).map($Ty)
}
#[cfg(not(feature = "unstable"))]
#[inline]
pub fn new(n: $Int) -> Option<Self> {
if n != 0 {
Some($Ty(n))
} else {
None
}
}
#[cfg(feature = "unstable")]
#[inline]
pub fn get(self) -> $Int {
self.0.get()
}
#[cfg(not(feature = "unstable"))]
#[inline]
pub fn get(self) -> $Int {
self.0
}
}
impl_nonzero_fmt! {
(Debug, Display, Binary, Octal, LowerHex, UpperHex) for $Ty
}
impl serde::Serialize for $Ty {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: serde::Serializer
{
self.get().serialize(serializer)
}
}
impl<'de> serde::Deserialize<'de> for $Ty {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: serde::Deserializer<'de>
{
let value = <$Int>::deserialize(deserializer)?;
match <$Ty>::new(value) {
Some(nonzero) => Ok(nonzero),
None => Err(serde::de::Error::custom("expected a non-zero value")),
}
}
}
)+
}
}
nonzero_integers! {
NonZeroU8(u8);
NonZeroU16(u16);
NonZeroU32(u32);
NonZeroU64(u64);
NonZeroUsize(usize);
}

View file

@ -14,4 +14,3 @@ doctest = false
[dependencies]
lazy_static = "1"
log = "0.4"
nonzero = {path = "../nonzero"}

View file

@ -10,12 +10,11 @@
//! It provides the same interface as https://github.com/rust-lang/rust/blob/master/src/libstd/sys/common/remutex.rs
//! so if those types are ever exported, we should be able to replace this implemtation.
extern crate nonzero;
#[macro_use] extern crate lazy_static;
#[macro_use] extern crate log;
use nonzero::NonZeroUsize;
use std::cell::{Cell, UnsafeCell};
use std::num::NonZeroUsize;
use std::ops::Deref;
use std::sync::{LockResult, Mutex, MutexGuard, PoisonError, TryLockError, TryLockResult};
use std::sync::atomic::{AtomicUsize, Ordering};

View file

@ -21,7 +21,6 @@ webrender_debugger = ["webrender/debugger"]
oculusvr = ["webvr/oculusvr"]
unstable = [
"euclid/unstable",
"msg/unstable",
"profile/unstable",
"script/unstable",
]