cleanedup uint.rs, converted spaces to tabs

This commit is contained in:
debris 2015-12-04 03:02:53 +01:00
parent 668d735fa7
commit 40f5bb6da2

View File

@ -22,7 +22,7 @@
///!
use std::fmt;
use std::cmp::{Ord, PartialOrd, Ordering};
use std::cmp::*;
use std::ops::*;
use std::str::FromStr;
use rustc_serialize::hex::{FromHex, FromHexError};
@ -37,124 +37,11 @@ macro_rules! impl_map_from {
}
}
macro_rules! impl_array_newtype {
($thing:ident, $ty:ty, $len:expr) => {
impl $thing {
#[inline]
/// Converts the object to a raw pointer
pub fn as_ptr(&self) -> *const $ty {
let &$thing(ref dat) = self;
dat.as_ptr()
}
#[inline]
/// Converts the object to a mutable raw pointer
pub fn as_mut_ptr(&mut self) -> *mut $ty {
let &mut $thing(ref mut dat) = self;
dat.as_mut_ptr()
}
#[inline]
/// Returns the length of the object as an array
pub fn len(&self) -> usize { $len }
#[inline]
/// Returns whether the object, as an array, is empty. Always false.
pub fn is_empty(&self) -> bool { false }
}
impl<'a> From<&'a [$ty]> for $thing {
fn from(data: &'a [$ty]) -> $thing {
assert_eq!(data.len(), $len);
unsafe {
use std::intrinsics::copy_nonoverlapping;
use std::mem;
let mut ret: $thing = mem::uninitialized();
copy_nonoverlapping(data.as_ptr(),
ret.as_mut_ptr(),
mem::size_of::<$thing>());
ret
}
}
}
impl Index<usize> for $thing {
type Output = $ty;
#[inline]
fn index(&self, index: usize) -> &$ty {
let &$thing(ref dat) = self;
&dat[index]
}
}
impl_index_newtype!($thing, $ty);
impl PartialEq for $thing {
#[inline]
fn eq(&self, other: &$thing) -> bool {
&self[..] == &other[..]
}
}
impl Eq for $thing {}
impl Clone for $thing {
#[inline]
fn clone(&self) -> $thing {
$thing::from(&self[..])
}
}
impl Copy for $thing {}
}
}
macro_rules! impl_index_newtype {
($thing:ident, $ty:ty) => {
impl Index<Range<usize>> for $thing {
type Output = [$ty];
#[inline]
fn index(&self, index: Range<usize>) -> &[$ty] {
&self.0[index]
}
}
impl Index<RangeTo<usize>> for $thing {
type Output = [$ty];
#[inline]
fn index(&self, index: RangeTo<usize>) -> &[$ty] {
&self.0[index]
}
}
impl Index<RangeFrom<usize>> for $thing {
type Output = [$ty];
#[inline]
fn index(&self, index: RangeFrom<usize>) -> &[$ty] {
&self.0[index]
}
}
impl Index<RangeFull> for $thing {
type Output = [$ty];
#[inline]
fn index(&self, _: RangeFull) -> &[$ty] {
&self.0[..]
}
}
}
}
macro_rules! construct_uint {
($name:ident, $n_words:expr) => (
/// Little-endian large integer type
#[derive(Copy, Clone, Eq, PartialEq)]
pub struct $name(pub [u64; $n_words]);
impl_array_newtype!($name, u64, $n_words);
impl $name {
/// Conversion to u32