Upgrade to rustc 551a74dddd84cf01440ee84148ebd18bc68bd7c8.

This commit is contained in:
Simon Sapin 2015-04-23 00:14:02 +02:00 committed by Josh Matthews
parent 7b87085c18
commit ef8edd4e87
168 changed files with 2247 additions and 2408 deletions

View file

@ -18,9 +18,6 @@ doctest = false
[dependencies.plugins]
path = "../plugins"
[dependencies.cssparser]
git = "https://github.com/servo/rust-cssparser"
[dependencies.selectors]
git = "https://github.com/servo/rust-selectors"
@ -47,5 +44,9 @@ bitflags = "*"
libc = "*"
rand = "*"
rustc-serialize = "0.3"
text_writer = "0.1.1"
time = "0.1.12"
smallvec = "0.1"
num_cpus = "0.2.2"
fnv = "1.0"
cssparser = "0.3.1"
num = "0.1.24"

View file

@ -7,22 +7,21 @@
//! This is based on `WebCore/platform/graphics/UnitBezier.h` in WebKit.
use geom::point::Point2D;
use std::num::Float;
const NEWTON_METHOD_ITERATIONS: u8 = 8;
pub struct Bezier {
ax: f64,
bx: f64,
cx: f64,
ay: f64,
by: f64,
cy: f64,
ax: f32,
bx: f32,
cx: f32,
ay: f32,
by: f32,
cy: f32,
}
impl Bezier {
#[inline]
pub fn new(p1: Point2D<f64>, p2: Point2D<f64>) -> Bezier {
pub fn new(p1: Point2D<f32>, p2: Point2D<f32>) -> Bezier {
let cx = 3.0 * p1.x;
let bx = 3.0 * (p2.x - p1.x) - cx;
@ -40,23 +39,23 @@ impl Bezier {
}
#[inline]
fn sample_curve_x(&self, t: f64) -> f64 {
fn sample_curve_x(&self, t: f32) -> f32 {
// ax * t^3 + bx * t^2 + cx * t
((self.ax * t + self.bx) * t + self.cx) * t
}
#[inline]
fn sample_curve_y(&self, t: f64) -> f64 {
fn sample_curve_y(&self, t: f32) -> f32 {
((self.ay * t + self.by) * t + self.cy) * t
}
#[inline]
fn sample_curve_derivative_x(&self, t: f64) -> f64 {
fn sample_curve_derivative_x(&self, t: f32) -> f32 {
(3.0 * self.ax * t + 2.0 * self.bx) * t + self.cx
}
#[inline]
fn solve_curve_x(&self, x: f64, epsilon: f64) -> f64 {
fn solve_curve_x(&self, x: f32, epsilon: f32) -> f32 {
// Fast path: Use Newton's method.
let mut t = x;
for _ in 0..NEWTON_METHOD_ITERATIONS {
@ -98,7 +97,7 @@ impl Bezier {
}
#[inline]
pub fn solve(&self, x: f64, epsilon: f64) -> f64 {
pub fn solve(&self, x: f32, epsilon: f32) -> f32 {
self.sample_curve_y(self.solve_curve_x(x, epsilon))
}
}
@ -107,9 +106,9 @@ trait ApproxEq {
fn approx_eq(self, value: Self, epsilon: Self) -> bool;
}
impl ApproxEq for f64 {
impl ApproxEq for f32 {
#[inline]
fn approx_eq(self, value: f64, epsilon: f64) -> bool {
fn approx_eq(self, value: f32, epsilon: f32) -> bool {
(self - value).abs() < epsilon
}
}

View file

@ -6,11 +6,10 @@
use cssparser::ToCss;
use std::ascii::AsciiExt;
use text_writer::TextWriter;
macro_rules! define_cursor {
($( $css: expr => $variant: ident = $value: expr, )+) => {
#[derive(Clone, Copy, PartialEq, Eq, FromPrimitive, Debug)]
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[repr(u8)]
pub enum Cursor {
$( $variant = $value ),+
@ -26,7 +25,7 @@ macro_rules! define_cursor {
}
impl ToCss for Cursor {
fn to_css<W>(&self, dest: &mut W) -> ::text_writer::Result where W: TextWriter {
fn to_css<W>(&self, dest: &mut W) -> ::std::fmt::Result where W: ::std::fmt::Write {
match self {
$( &Cursor::$variant => dest.write_str($css) ),+
}

View file

@ -170,7 +170,9 @@ impl<T: Send + 'static> BufferPool<T> {
}
}
}
}
impl<T> BufferPool<T> {
fn free(&self, buf: Box<Buffer<T>>) {
let mut pool = self.pool.lock().unwrap();
match pool.iter().position(|v| v.size() > buf.size()) {
@ -331,8 +333,7 @@ impl<T: Send + 'static> Deque<T> {
}
#[unsafe_destructor]
impl<T: Send + 'static> Drop for Deque<T> {
impl<T> Drop for Deque<T> {
fn drop(&mut self) {
let t = self.top.load(SeqCst);
let b = self.bottom.load(SeqCst);
@ -351,7 +352,7 @@ fn buffer_alloc_size<T>(log_size: usize) -> usize {
(1 << log_size) * size_of::<T>()
}
impl<T: Send> Buffer<T> {
impl<T> Buffer<T> {
unsafe fn new(log_size: usize) -> Buffer<T> {
let size = buffer_alloc_size::<T>(log_size);
let buffer = allocate(size, min_align_of::<T>());
@ -399,8 +400,7 @@ impl<T: Send> Buffer<T> {
}
}
#[unsafe_destructor]
impl<T: Send> Drop for Buffer<T> {
impl<T> Drop for Buffer<T> {
fn drop(&mut self) {
// It is assumed that all buffers are empty on drop.
let size = buffer_alloc_size::<T>(self.log_size);

View file

@ -10,7 +10,6 @@ use geom::num::Zero;
use std::default::Default;
use std::i32;
use std::num::{Float, NumCast, ToPrimitive};
use std::fmt;
use std::ops::{Add, Sub, Neg, Mul, Div, Rem};
@ -116,13 +115,13 @@ pub const MAX_AU: Au = Au(i32::MAX);
impl Encodable for Au {
fn encode<S: Encoder>(&self, e: &mut S) -> Result<(), S::Error> {
e.emit_f64(to_frac_px(*self))
e.emit_f64(self.to_subpx())
}
}
impl fmt::Debug for Au {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}px", to_frac_px(*self))
write!(f, "{}px", self.to_subpx())
}}
impl Add for Au {
@ -188,40 +187,6 @@ impl Neg for Au {
}
}
impl NumCast for Au {
#[inline]
fn from<T:ToPrimitive>(n: T) -> Option<Au> {
Some(Au(n.to_i32().unwrap()))
}
}
impl ToPrimitive for Au {
#[inline]
fn to_i64(&self) -> Option<i64> {
let Au(s) = *self;
Some(s as i64)
}
#[inline]
fn to_u64(&self) -> Option<u64> {
let Au(s) = *self;
Some(s as u64)
}
#[inline]
fn to_f32(&self) -> Option<f32> {
let Au(s) = *self;
s.to_f32()
}
#[inline]
fn to_f64(&self) -> Option<f64> {
let Au(s) = *self;
s.to_f64()
}
}
impl Au {
/// FIXME(pcwalton): Workaround for lack of cross crate inlining of newtype structs!
#[inline]
@ -230,19 +195,19 @@ impl Au {
}
#[inline]
pub fn scale_by(self, factor: f64) -> Au {
pub fn scale_by(self, factor: f32) -> Au {
let Au(s) = self;
Au(((s as f64) * factor) as i32)
Au(((s as f32) * factor) as i32)
}
#[inline]
pub fn from_px(px: isize) -> Au {
NumCast::from(px * 60).unwrap()
Au((px * 60) as i32)
}
#[inline]
pub fn from_page_px(px: Length<PagePx, f32>) -> Au {
NumCast::from(px.get() * 60f32).unwrap()
Au((px.get() * 60f32) as i32)
}
/// Rounds this app unit down to the previous (left or top) pixel and returns it.
@ -297,7 +262,7 @@ impl Au {
#[inline]
pub fn from_frac_px(px: f64) -> Au {
Au((px * 60f64) as i32)
Au((px * 60.) as i32)
}
#[inline]
@ -317,20 +282,20 @@ impl Au {
// assumes 72 points per inch, and 96 px per inch
pub fn pt_to_px(pt: f64) -> f64 {
pt / 72f64 * 96f64
pt / 72. * 96.
}
// assumes 72 points per inch, and 96 px per inch
pub fn px_to_pt(px: f64) -> f64 {
px / 96f64 * 72f64
px / 96. * 72.
}
pub fn from_frac_px(px: f64) -> Au {
Au((px * 60f64) as i32)
Au((px * 60.) as i32)
}
pub fn from_px(px: isize) -> Au {
NumCast::from(px * 60).unwrap()
Au::from_px(px)
}
pub fn to_px(au: Au) -> isize {
@ -338,20 +303,20 @@ pub fn to_px(au: Au) -> isize {
(a / 60) as isize
}
pub fn to_frac_px(au: Au) -> f64 {
pub fn to_frac_px(au: Au) -> f32 {
let Au(a) = au;
(a as f64) / 60f64
(a as f32) / 60.
}
// assumes 72 points per inch, and 96 px per inch
pub fn from_pt(pt: f64) -> Au {
from_px((pt / 72f64 * 96f64) as isize)
pub fn from_pt(pt: f32) -> Au {
from_px((pt / 72. * 96.) as isize)
}
// assumes 72 points per inch, and 96 px per inch
pub fn to_pt(au: Au) -> f64 {
pub fn to_pt(au: Au) -> f32 {
let Au(a) = au;
(a as f64) / 60f64 * 72f64 / 96f64
(a as f32) / 60. * 72. / 96.
}
/// Returns true if the rect contains the given point. Points on the top or left sides of the rect

View file

@ -7,16 +7,14 @@
#![feature(collections)]
#![feature(core)]
#![feature(exit_status)]
#![feature(hash)]
#![feature(io)]
#![feature(optin_builtin_traits)]
#![feature(path)]
#![cfg_attr(not(target_os = "android"), feature(path_ext))]
#![feature(plugin)]
#![feature(rustc_private)]
#![feature(step_by)]
#![feature(step_trait)]
#![feature(std_misc)]
#![feature(unicode)]
#![feature(unsafe_destructor)]
#![feature(zero_one)]
#![plugin(string_cache_plugin)]
@ -25,29 +23,31 @@
extern crate azure;
extern crate alloc;
#[macro_use] extern crate bitflags;
extern crate cssparser;
#[macro_use] extern crate cssparser;
extern crate fnv as fnv_;
extern crate geom;
extern crate getopts;
extern crate layers;
extern crate libc;
#[no_link] #[macro_use] extern crate cssparser;
extern crate num as num_lib;
extern crate num_cpus;
extern crate rand;
extern crate "rustc-serialize" as rustc_serialize;
extern crate text_writer;
extern crate rustc_serialize;
extern crate selectors;
extern crate smallvec as smallvec_;
extern crate string_cache;
pub use selectors::smallvec;
use std::sync::Arc;
pub use fnv_ as fnv;
pub use smallvec_ as smallvec;
pub mod bezier;
pub mod cache;
pub mod cursor;
pub mod debug_utils;
pub mod deque;
pub mod linked_list;
pub mod fnv;
pub mod geometry;
pub mod logical_geometry;
pub mod mem;

View file

@ -154,7 +154,6 @@ unsafe fn linked_list2_check() {
// Currently, types that implement the Drop type are larger than those that don't. Because
// LinkedList implements Drop, LinkedList2 must also so that linked_list2_check() doesn't fail.
#[unsafe_destructor]
impl<T> Drop for LinkedList2<T> {
fn drop(&mut self) {}
}

View file

@ -11,13 +11,13 @@ use geom::scale_factor::ScaleFactor;
use geom::size::TypedSize2D;
use layers::geometry::DevicePixel;
use getopts;
use num_cpus;
use std::collections::HashSet;
use std::cmp;
use std::env;
use std::io::{self, Write};
use std::mem;
use std::ptr;
use std::rt;
/// Global flags for Servo, currently set on the command line.
#[derive(Clone)]
@ -307,7 +307,7 @@ pub fn from_cmdline_args(args: &[String]) -> bool {
let mut paint_threads: usize = match opt_match.opt_str("t") {
Some(paint_threads_str) => paint_threads_str.parse().unwrap(),
None => cmp::max(rt::default_sched_threads() * 3 / 4, 1),
None => cmp::max(num_cpus::get() * 3 / 4, 1),
};
// If only the flag is present, default to a 5 second period for both profilers.
@ -322,7 +322,7 @@ pub fn from_cmdline_args(args: &[String]) -> bool {
let mut layout_threads: usize = match opt_match.opt_str("y") {
Some(layout_threads_str) => layout_threads_str.parse().unwrap(),
None => cmp::max(rt::default_sched_threads() * 3 / 4, 1),
None => cmp::max(num_cpus::get() * 3 / 4, 1),
};
let nonincremental_layout = opt_match.opt_present("i");

View file

@ -2,12 +2,38 @@
* 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 std::cmp::{max, min};
use num_lib;
use std::cmp::{self, max, min};
use std::fmt;
use std::iter;
use std::marker::PhantomData;
use std::num::{self, Int};
use std::num;
use std::ops;
pub trait Int:
Copy
+ ops::Add<Self, Output=Self>
+ ops::Sub<Self, Output=Self>
+ cmp::Ord
{
fn zero() -> Self;
fn one() -> Self;
fn max_value() -> Self;
fn from_usize(n: usize) -> Option<Self>;
}
impl Int for isize {
fn zero() -> isize { 0 }
fn one() -> isize { 1 }
fn max_value() -> isize { ::std::isize::MAX }
fn from_usize(n: usize) -> Option<isize> { num_lib::NumCast::from(n) }
}
impl Int for usize {
fn zero() -> usize { 0 }
fn one() -> usize { 1 }
fn max_value() -> usize { ::std::usize::MAX }
fn from_usize(n: usize) -> Option<usize> { Some(n) }
}
/// An index type to be used by a `Range`
pub trait RangeIndex: Int + fmt::Debug {
type Index;
@ -61,32 +87,14 @@ macro_rules! int_range_index {
}
}
impl ::std::num::Int for $Self_ {
fn zero() -> $Self_ { $Self_(0) }
fn one() -> $Self_ { $Self_(1) }
fn min_value() -> $Self_ { $Self_(::std::num::Int::min_value()) }
fn max_value() -> $Self_ { $Self_(::std::num::Int::max_value()) }
fn count_ones(self) -> u32 { self.get().count_ones() }
fn leading_zeros(self) -> u32 { self.get().leading_zeros() }
fn trailing_zeros(self) -> u32 { self.get().trailing_zeros() }
fn rotate_left(self, n: u32) -> $Self_ { $Self_(self.get().rotate_left(n)) }
fn rotate_right(self, n: u32) -> $Self_ { $Self_(self.get().rotate_right(n)) }
fn swap_bytes(self) -> $Self_ { $Self_(self.get().swap_bytes()) }
fn checked_add(self, other: $Self_) -> Option<$Self_> {
self.get().checked_add(other.get()).map($Self_)
}
fn checked_sub(self, other: $Self_) -> Option<$Self_> {
self.get().checked_sub(other.get()).map($Self_)
}
fn checked_mul(self, other: $Self_) -> Option<$Self_> {
self.get().checked_mul(other.get()).map($Self_)
}
fn checked_div(self, other: $Self_) -> Option<$Self_> {
self.get().checked_div(other.get()).map($Self_)
}
impl $crate::range::Int for $Self_ {
fn zero() -> $Self_ { $Self_($crate::range::Int::zero()) }
fn one() -> $Self_ { $Self_($crate::range::Int::one()) }
fn max_value() -> $Self_ { $Self_($crate::range::Int::max_value()) }
fn from_usize(n: usize) -> Option<$Self_> { $crate::range::Int::from_usize(n).map($Self_) }
}
impl Add<$Self_> for $Self_ {
impl ::std::ops::Add<$Self_> for $Self_ {
type Output = $Self_;
#[inline]
@ -95,7 +103,7 @@ macro_rules! int_range_index {
}
}
impl Sub<$Self_> for $Self_ {
impl ::std::ops::Sub<$Self_> for $Self_ {
type Output = $Self_;
#[inline]
@ -104,16 +112,7 @@ macro_rules! int_range_index {
}
}
impl Mul<$Self_> for $Self_ {
type Output = $Self_;
#[inline]
fn mul(self, other: $Self_) -> $Self_ {
$Self_(self.get() * other.get())
}
}
impl Neg for $Self_ {
impl ::std::ops::Neg for $Self_ {
type Output = $Self_;
#[inline]
@ -121,105 +120,6 @@ macro_rules! int_range_index {
$Self_(-self.get())
}
}
impl ToPrimitive for $Self_ {
fn to_i64(&self) -> Option<i64> {
Some(self.get() as i64)
}
fn to_u64(&self) -> Option<u64> {
Some(self.get() as u64)
}
}
impl ::std::num::NumCast for $Self_ {
fn from<T: ToPrimitive>(n: T) -> Option<$Self_> {
n.to_isize().map($Self_)
}
}
impl Div<$Self_> for $Self_ {
type Output = $Self_;
fn div(self, other: $Self_) -> $Self_ {
$Self_(self.get() / other.get())
}
}
impl Rem<$Self_> for $Self_ {
type Output = $Self_;
fn rem(self, other: $Self_) -> $Self_ {
$Self_(self.get() % other.get())
}
}
impl Not for $Self_ {
type Output = $Self_;
fn not(self) -> $Self_ {
$Self_(!self.get())
}
}
impl BitAnd<$Self_> for $Self_ {
type Output = $Self_;
fn bitand(self, other: $Self_) -> $Self_ {
$Self_(self.get() & other.get())
}
}
impl BitOr<$Self_> for $Self_ {
type Output = $Self_;
fn bitor(self, other: $Self_) -> $Self_ {
$Self_(self.get() | other.get())
}
}
impl BitXor<$Self_> for $Self_ {
type Output = $Self_;
fn bitxor(self, other: $Self_) -> $Self_ {
$Self_(self.get() ^ other.get())
}
}
impl Shl<usize> for $Self_ {
type Output = $Self_;
fn shl(self, n: usize) -> $Self_ {
$Self_(self.get() << n)
}
}
impl Shr<usize> for $Self_ {
type Output = $Self_;
fn shr(self, n: usize) -> $Self_ {
$Self_(self.get() >> n)
}
}
impl ::std::num::wrapping::WrappingOps for $Self_ {
fn wrapping_add(self, rhs: $Self_) -> $Self_ {
$Self_(self.get().wrapping_add(rhs.get()))
}
fn wrapping_sub(self, rhs: $Self_) -> $Self_ {
$Self_(self.get().wrapping_sub(rhs.get()))
}
fn wrapping_mul(self, rhs: $Self_) -> $Self_ {
$Self_(self.get().wrapping_mul(rhs.get()))
}
}
impl ::std::num::wrapping::OverflowingOps for $Self_ {
fn overflowing_add(self, rhs: $Self_) -> ($Self_, bool) {
let (x, b) = self.get().overflowing_add(rhs.get());
($Self_(x), b)
}
fn overflowing_sub(self, rhs: $Self_) -> ($Self_, bool) {
let (x, b) = self.get().overflowing_sub(rhs.get());
($Self_(x), b)
}
fn overflowing_mul(self, rhs: $Self_) -> ($Self_, bool) {
let (x, b) = self.get().overflowing_mul(rhs.get());
($Self_(x), b)
}
}
)
}
@ -246,12 +146,13 @@ pub fn each_index<T: Int, I: RangeIndex<Index=T>>(start: I, stop: I) -> EachInde
EachIndex { it: start.get()..stop.get(), phantom: PhantomData }
}
impl<T: Int, I: RangeIndex<Index=T>> Iterator for EachIndex<T, I> {
impl<T: Int, I: RangeIndex<Index=T>> Iterator for EachIndex<T, I>
where T: Int + num::One + iter::Step, for<'a> &'a T: ops::Add<&'a T, Output = T> {
type Item = I;
#[inline]
fn next(&mut self) -> Option<I> {
self.it.next().map(|i| RangeIndex::new(i))
self.it.next().map(RangeIndex::new)
}
#[inline]
@ -407,7 +308,7 @@ impl<T: Int, I: RangeIndex<Index=T>> Range<I> {
#[inline]
pub fn is_valid_for_string(&self, s: &str) -> bool {
let s_len = s.len();
match num::cast::<usize, T>(s_len) {
match Int::from_usize(s_len) {
Some(len) => {
let len = RangeIndex::new(len);
self.begin() < len

View file

@ -8,7 +8,7 @@ use std::path::PathBuf;
#[cfg(target_os = "android")]
pub fn resources_dir_path() -> PathBuf {
PathBuf::new("/sdcard/servo/")
PathBuf::from("/sdcard/servo/")
}
#[cfg(not(target_os = "android"))]
@ -18,7 +18,7 @@ pub fn resources_dir_path() -> PathBuf {
use std::fs::PathExt;
match opts::get().resources_path {
Some(ref path) => PathBuf::new(path),
Some(ref path) => PathBuf::from(path),
None => {
// FIXME: Find a way to not rely on the executable being
// under `<servo source>/components/servo/target`

View file

@ -7,11 +7,11 @@ use geometry::Au;
use cssparser::{self, RGBA, Color};
use libc::c_char;
use num_lib::ToPrimitive;
use std::ascii::AsciiExt;
use std::borrow::ToOwned;
use std::ffi::CStr;
use std::iter::Filter;
use std::num::{Int, ToPrimitive};
use std::ops::Deref;
use std::str::{from_utf8, FromStr, Split};
@ -130,7 +130,7 @@ pub fn parse_unsigned_integer<T: Iterator<Item=char>>(input: T) -> Option<u32> {
#[derive(Copy, Clone)]
pub enum LengthOrPercentageOrAuto {
Auto,
Percentage(f64),
Percentage(f32),
Length(Au),
}
@ -171,9 +171,9 @@ pub fn parse_length(mut value: &str) -> LengthOrPercentageOrAuto {
value = &value[..end_index];
if found_percent {
let result: Result<f64, _> = FromStr::from_str(value);
let result: Result<f32, _> = FromStr::from_str(value);
match result {
Ok(number) => return LengthOrPercentageOrAuto::Percentage((number as f64) / 100.0),
Ok(number) => return LengthOrPercentageOrAuto::Percentage((number as f32) / 100.0),
Err(_) => return LengthOrPercentageOrAuto::Auto,
}
}
@ -243,7 +243,7 @@ pub fn parse_legacy_color(mut input: &str) -> Result<RGBA,()> {
}
// Step 9.
if input.char_at(0) == '#' {
if input.as_bytes()[0] == b'#' {
input = &input[1..]
}
@ -324,7 +324,7 @@ pub struct LowercaseString {
impl LowercaseString {
pub fn new(s: &str) -> LowercaseString {
LowercaseString {
inner: s.chars().map(|c| c.to_lowercase()).collect(),
inner: s.to_lowercase(),
}
}
}

View file

@ -44,7 +44,7 @@ impl TaskPool {
loop {
let job = rx.lock().unwrap().recv();
match job {
Ok(job) => job.invoke(()),
Ok(job) => job.call_box(()),
Err(..) => break,
}
}
@ -54,6 +54,6 @@ impl TaskPool {
pub fn execute<F>(&self, job: F)
where F: FnOnce() + Send + 'static
{
self.tx.send(Thunk::new(job)).unwrap();
self.tx.send(Box::new(job)).unwrap();
}
}

View file

@ -2,10 +2,11 @@
* 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 selectors::smallvec::VecLike;
use super::smallvec::VecLike;
use std::cmp::{PartialOrd, PartialEq, Ordering};
use std::iter::range_step;
use std::marker::PhantomData;
use std::ops;
/// FIXME(pcwalton): Workaround for lack of unboxed closures. This is called in
/// performance-critical code, so a closure is insufficient.
@ -68,7 +69,7 @@ impl<T:PartialEq + PartialOrd + Ord> Comparator<T,T> for DefaultComparator {
// TODO(pcwalton): Speed up with SIMD, or better yet, find some way to not do this.
pub fn byte_swap(data: &mut [u8]) {
let length = data.len();
for i in range_step(0, length, 4) {
for i in (0..length).step_by(4) {
let r = data[i + 2];
data[i + 2] = data[i + 0];
data[i + 0] = r;
@ -76,14 +77,16 @@ pub fn byte_swap(data: &mut [u8]) {
}
/// A `VecLike` that only tracks whether or not something was ever pushed to it.
pub struct ForgetfulSink {
pub struct ForgetfulSink<T> {
empty: bool,
_data: PhantomData<T>,
}
impl ForgetfulSink {
pub fn new() -> ForgetfulSink {
impl<T> ForgetfulSink<T> {
pub fn new() -> ForgetfulSink<T> {
ForgetfulSink {
empty: true,
_data: PhantomData,
}
}
@ -92,19 +95,50 @@ impl ForgetfulSink {
}
}
impl<T> VecLike<T> for ForgetfulSink {
#[inline]
fn vec_len(&self) -> usize {
unreachable!()
}
#[inline]
fn vec_push(&mut self, _value: T) {
self.empty = false;
}
#[inline]
fn vec_slice_mut<'a>(&'a mut self, _start: usize, _end: usize) -> &'a mut [T] {
impl<T> ops::Deref for ForgetfulSink<T> {
type Target = [T];
fn deref(&self) -> &[T] {
unreachable!()
}
}
impl<T> ops::DerefMut for ForgetfulSink<T> {
fn deref_mut(&mut self) -> &mut [T] {
unreachable!()
}
}
macro_rules! impl_index {
($index_type: ty, $output_type: ty) => {
impl<T> ops::Index<$index_type> for ForgetfulSink<T> {
type Output = $output_type;
fn index(&self, _index: $index_type) -> &$output_type {
unreachable!()
}
}
impl<T> ops::IndexMut<$index_type> for ForgetfulSink<T> {
fn index_mut(&mut self, _index: $index_type) -> &mut $output_type {
unreachable!()
}
}
}
}
impl_index!(usize, T);
impl_index!(ops::Range<usize>, [T]);
impl_index!(ops::RangeFrom<usize>, [T]);
impl_index!(ops::RangeTo<usize>, [T]);
impl_index!(ops::RangeFull, [T]);
impl<T> VecLike<T> for ForgetfulSink<T> {
#[inline]
fn len(&self) -> usize {
unreachable!()
}
#[inline]
fn push(&mut self, _value: T) {
self.empty = false;
}
}