Use NonZeroU32 in canvas_traits

This commit is contained in:
Simon Sapin 2017-10-12 00:49:39 +02:00
parent ecf3b05153
commit 5e72173e8c
6 changed files with 16 additions and 5 deletions

1
Cargo.lock generated
View file

@ -326,6 +326,7 @@ dependencies = [
"heapsize_derive 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"nonzero 0.0.1",
"offscreen_gl_context 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)",
"servo_config 0.0.1",

View file

@ -9,6 +9,9 @@ publish = false
name = "canvas_traits"
path = "lib.rs"
[features]
unstable = ["nonzero/unstable"]
[dependencies]
cssparser = "0.22.0"
euclid = "0.15"
@ -16,6 +19,7 @@ heapsize = "0.4"
heapsize_derive = "0.1"
ipc-channel = "0.8"
lazy_static = "0.2"
nonzero = {path = "../nonzero"}
offscreen_gl_context = { version = "0.11", features = ["serde"] }
serde = "1.0"
servo_config = {path = "../config"}

View file

@ -4,17 +4,18 @@
#![crate_name = "canvas_traits"]
#![crate_type = "rlib"]
#![feature(nonzero)]
#![cfg_attr(feature = "unstable", feature(nonzero))]
#![deny(unsafe_code)]
extern crate core;
extern crate cssparser;
extern crate euclid;
extern crate heapsize;
#[macro_use] extern crate heapsize_derive;
extern crate ipc_channel;
#[macro_use] extern crate lazy_static;
extern crate nonzero;
extern crate offscreen_gl_context;
#[macro_use] extern crate serde;
extern crate servo_config;

View file

@ -2,8 +2,8 @@
* 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/. */
use core::nonzero::NonZero;
use euclid::Size2D;
use nonzero::NonZeroU32;
use offscreen_gl_context::{GLContextAttributes, GLLimits};
use std::fmt;
use webrender_api;
@ -242,13 +242,13 @@ pub enum WebGLCommand {
macro_rules! define_resource_id_struct {
($name:ident) => {
#[derive(Clone, Copy, Eq, Hash, PartialEq)]
pub struct $name(NonZero<u32>);
pub struct $name(NonZeroU32);
impl $name {
#[allow(unsafe_code)]
#[inline]
pub unsafe fn new(id: u32) -> Self {
$name(NonZero::new_unchecked(id))
$name(NonZeroU32::new_unchecked(id))
}
#[inline]

View file

@ -39,6 +39,10 @@ mod imp {
}
}
pub unsafe fn new_unchecked(x: u32) -> Self {
NonZeroU32(x)
}
pub fn get(self) -> u32 {
self.0
}

View file

@ -22,6 +22,7 @@ unstable = [
"euclid/unstable",
"layout_thread/unstable",
"msg/unstable",
"canvas_traits/unstable",
"compositing/unstable",
"constellation/unstable",
]