mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Remove components/nonzero, use std::num::NonZero instead
This commit is contained in:
parent
d55a003c92
commit
e39f741321
15 changed files with 5 additions and 158 deletions
11
Cargo.lock
generated
11
Cargo.lock
generated
|
@ -296,7 +296,6 @@ dependencies = [
|
||||||
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"malloc_size_of 0.0.1",
|
"malloc_size_of 0.0.1",
|
||||||
"malloc_size_of_derive 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)",
|
"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 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)",
|
"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)",
|
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"msg 0.0.1",
|
"msg 0.0.1",
|
||||||
"net_traits 0.0.1",
|
"net_traits 0.0.1",
|
||||||
"nonzero 0.0.1",
|
|
||||||
"profile_traits 0.0.1",
|
"profile_traits 0.0.1",
|
||||||
"script_traits 0.0.1",
|
"script_traits 0.0.1",
|
||||||
"servo_config 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)",
|
"bitflags 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"malloc_size_of 0.0.1",
|
"malloc_size_of 0.0.1",
|
||||||
"malloc_size_of_derive 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)",
|
"serde 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"size_of_test 0.0.1",
|
"size_of_test 0.0.1",
|
||||||
"webrender_api 0.57.2 (git+https://github.com/servo/webrender)",
|
"webrender_api 0.57.2 (git+https://github.com/servo/webrender)",
|
||||||
|
@ -1951,13 +1948,6 @@ name = "nom"
|
||||||
version = "1.2.4"
|
version = "1.2.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
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]]
|
[[package]]
|
||||||
name = "num-integer"
|
name = "num-integer"
|
||||||
version = "0.1.38"
|
version = "0.1.38"
|
||||||
|
@ -2862,7 +2852,6 @@ version = "0.0.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"nonzero 0.0.1",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -17,7 +17,6 @@ gleam = "0.5.1"
|
||||||
lazy_static = "1"
|
lazy_static = "1"
|
||||||
malloc_size_of = { path = "../malloc_size_of" }
|
malloc_size_of = { path = "../malloc_size_of" }
|
||||||
malloc_size_of_derive = { path = "../malloc_size_of_derive" }
|
malloc_size_of_derive = { path = "../malloc_size_of_derive" }
|
||||||
nonzero = {path = "../nonzero"}
|
|
||||||
offscreen_gl_context = {version = "0.17", features = ["serde"]}
|
offscreen_gl_context = {version = "0.17", features = ["serde"]}
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
serde_bytes = "0.10"
|
serde_bytes = "0.10"
|
||||||
|
|
|
@ -14,7 +14,6 @@ extern crate ipc_channel;
|
||||||
#[macro_use] extern crate lazy_static;
|
#[macro_use] extern crate lazy_static;
|
||||||
extern crate malloc_size_of;
|
extern crate malloc_size_of;
|
||||||
#[macro_use] extern crate malloc_size_of_derive;
|
#[macro_use] extern crate malloc_size_of_derive;
|
||||||
extern crate nonzero;
|
|
||||||
extern crate offscreen_gl_context;
|
extern crate offscreen_gl_context;
|
||||||
#[macro_use] extern crate serde;
|
#[macro_use] extern crate serde;
|
||||||
extern crate serde_bytes;
|
extern crate serde_bytes;
|
||||||
|
|
|
@ -4,9 +4,9 @@
|
||||||
|
|
||||||
use euclid::Size2D;
|
use euclid::Size2D;
|
||||||
use gleam::gl;
|
use gleam::gl;
|
||||||
use nonzero::NonZeroU32;
|
|
||||||
use offscreen_gl_context::{GLContextAttributes, GLLimits};
|
use offscreen_gl_context::{GLContextAttributes, GLLimits};
|
||||||
use serde_bytes::ByteBuf;
|
use serde_bytes::ByteBuf;
|
||||||
|
use std::num::NonZeroU32;
|
||||||
use webrender_api::{DocumentId, ImageKey, PipelineId};
|
use webrender_api::{DocumentId, ImageKey, PipelineId};
|
||||||
|
|
||||||
/// Sender type used in WebGLCommands.
|
/// Sender type used in WebGLCommands.
|
||||||
|
|
|
@ -24,7 +24,6 @@ libc = "0.2"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
msg = {path = "../msg"}
|
msg = {path = "../msg"}
|
||||||
net_traits = {path = "../net_traits"}
|
net_traits = {path = "../net_traits"}
|
||||||
nonzero = {path = "../nonzero"}
|
|
||||||
profile_traits = {path = "../profile_traits"}
|
profile_traits = {path = "../profile_traits"}
|
||||||
script_traits = {path = "../script_traits"}
|
script_traits = {path = "../script_traits"}
|
||||||
servo_config = {path = "../config"}
|
servo_config = {path = "../config"}
|
||||||
|
|
|
@ -18,7 +18,6 @@ use msg::constellation_msg::{PipelineId, PipelineIndex, PipelineNamespaceId};
|
||||||
use net_traits::image::base::Image;
|
use net_traits::image::base::Image;
|
||||||
#[cfg(feature = "gleam")]
|
#[cfg(feature = "gleam")]
|
||||||
use net_traits::image::base::PixelFormat;
|
use net_traits::image::base::PixelFormat;
|
||||||
use nonzero::NonZeroU32;
|
|
||||||
use profile_traits::time::{self, ProfilerCategory, profile};
|
use profile_traits::time::{self, ProfilerCategory, profile};
|
||||||
use script_traits::{AnimationState, AnimationTickType, ConstellationMsg, LayoutControlMsg};
|
use script_traits::{AnimationState, AnimationTickType, ConstellationMsg, LayoutControlMsg};
|
||||||
use script_traits::{MouseButton, MouseEventType, ScrollState, TouchEventType, TouchId};
|
use script_traits::{MouseButton, MouseEventType, ScrollState, TouchEventType, TouchId};
|
||||||
|
@ -30,6 +29,7 @@ use std::collections::HashMap;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs::{File, create_dir_all};
|
use std::fs::{File, create_dir_all};
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
use std::num::NonZeroU32;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::mpsc::Sender;
|
use std::sync::mpsc::Sender;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
|
@ -17,7 +17,6 @@ extern crate libc;
|
||||||
extern crate log;
|
extern crate log;
|
||||||
extern crate msg;
|
extern crate msg;
|
||||||
extern crate net_traits;
|
extern crate net_traits;
|
||||||
extern crate nonzero;
|
|
||||||
extern crate profile_traits;
|
extern crate profile_traits;
|
||||||
extern crate script_traits;
|
extern crate script_traits;
|
||||||
extern crate servo_config;
|
extern crate servo_config;
|
||||||
|
|
|
@ -11,15 +11,11 @@ path = "lib.rs"
|
||||||
test = false
|
test = false
|
||||||
doctest = false
|
doctest = false
|
||||||
|
|
||||||
[features]
|
|
||||||
unstable = ["nonzero/unstable"]
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bitflags = "1.0"
|
bitflags = "1.0"
|
||||||
malloc_size_of = { path = "../malloc_size_of" }
|
malloc_size_of = { path = "../malloc_size_of" }
|
||||||
malloc_size_of_derive = { path = "../malloc_size_of_derive" }
|
malloc_size_of_derive = { path = "../malloc_size_of_derive" }
|
||||||
nonzero = {path = "../nonzero"}
|
serde = "1.0.60"
|
||||||
serde = "1.0.14"
|
|
||||||
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
|
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
|
|
@ -5,9 +5,9 @@
|
||||||
//! The high-level interface from script to constellation. Using this abstract interface helps
|
//! The high-level interface from script to constellation. Using this abstract interface helps
|
||||||
//! reduce coupling between these two components.
|
//! reduce coupling between these two components.
|
||||||
|
|
||||||
use nonzero::NonZeroU32;
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
use std::num::NonZeroU32;
|
||||||
use webrender_api;
|
use webrender_api;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
||||||
|
@ -390,15 +390,11 @@ impl fmt::Display for HistoryStateId {
|
||||||
// We provide ids just for unit testing.
|
// We provide ids just for unit testing.
|
||||||
pub const TEST_NAMESPACE: PipelineNamespaceId = PipelineNamespaceId(1234);
|
pub const TEST_NAMESPACE: PipelineNamespaceId = PipelineNamespaceId(1234);
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
#[cfg(feature = "unstable")]
|
|
||||||
pub const TEST_PIPELINE_INDEX: PipelineIndex = unsafe { PipelineIndex(NonZeroU32::new_unchecked(5678)) };
|
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 };
|
pub const TEST_PIPELINE_ID: PipelineId = PipelineId { namespace_id: TEST_NAMESPACE, index: TEST_PIPELINE_INDEX };
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
#[cfg(feature = "unstable")]
|
|
||||||
pub const TEST_BROWSING_CONTEXT_INDEX: BrowsingContextIndex =
|
pub const TEST_BROWSING_CONTEXT_INDEX: BrowsingContextIndex =
|
||||||
unsafe { BrowsingContextIndex(NonZeroU32::new_unchecked(8765)) };
|
unsafe { BrowsingContextIndex(NonZeroU32::new_unchecked(8765)) };
|
||||||
#[cfg(feature = "unstable")]
|
|
||||||
pub const TEST_BROWSING_CONTEXT_ID: BrowsingContextId =
|
pub const TEST_BROWSING_CONTEXT_ID: BrowsingContextId =
|
||||||
BrowsingContextId { namespace_id: TEST_NAMESPACE, index: TEST_BROWSING_CONTEXT_INDEX };
|
BrowsingContextId { namespace_id: TEST_NAMESPACE, index: TEST_BROWSING_CONTEXT_INDEX };
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
extern crate bitflags;
|
extern crate bitflags;
|
||||||
#[macro_use] extern crate malloc_size_of;
|
#[macro_use] extern crate malloc_size_of;
|
||||||
#[macro_use] extern crate malloc_size_of_derive;
|
#[macro_use] extern crate malloc_size_of_derive;
|
||||||
extern crate nonzero;
|
|
||||||
#[macro_use] extern crate serde;
|
#[macro_use] extern crate serde;
|
||||||
extern crate webrender_api;
|
extern crate webrender_api;
|
||||||
|
|
||||||
|
|
|
@ -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"
|
|
|
@ -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);
|
|
||||||
}
|
|
|
@ -14,4 +14,3 @@ doctest = false
|
||||||
[dependencies]
|
[dependencies]
|
||||||
lazy_static = "1"
|
lazy_static = "1"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
nonzero = {path = "../nonzero"}
|
|
||||||
|
|
|
@ -10,12 +10,11 @@
|
||||||
//! It provides the same interface as https://github.com/rust-lang/rust/blob/master/src/libstd/sys/common/remutex.rs
|
//! 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.
|
//! 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 lazy_static;
|
||||||
#[macro_use] extern crate log;
|
#[macro_use] extern crate log;
|
||||||
|
|
||||||
use nonzero::NonZeroUsize;
|
|
||||||
use std::cell::{Cell, UnsafeCell};
|
use std::cell::{Cell, UnsafeCell};
|
||||||
|
use std::num::NonZeroUsize;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::sync::{LockResult, Mutex, MutexGuard, PoisonError, TryLockError, TryLockResult};
|
use std::sync::{LockResult, Mutex, MutexGuard, PoisonError, TryLockError, TryLockResult};
|
||||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
|
|
|
@ -21,7 +21,6 @@ webrender_debugger = ["webrender/debugger"]
|
||||||
oculusvr = ["webvr/oculusvr"]
|
oculusvr = ["webvr/oculusvr"]
|
||||||
unstable = [
|
unstable = [
|
||||||
"euclid/unstable",
|
"euclid/unstable",
|
||||||
"msg/unstable",
|
|
||||||
"profile/unstable",
|
"profile/unstable",
|
||||||
"script/unstable",
|
"script/unstable",
|
||||||
]
|
]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue