add constraints to Size trait

This commit is contained in:
Szymon Walter 2018-03-21 18:54:50 +01:00
parent c42fb978c2
commit 934266ca4b
7 changed files with 15 additions and 25 deletions

View file

@ -30,7 +30,7 @@ pub struct Ext2<S: Size, V: Volume<u8, Address<S>>> {
block_groups: Struct<Vec<BlockGroupDescriptor>, S>, block_groups: Struct<Vec<BlockGroupDescriptor>, S>,
} }
impl<S: Size + Copy, V: Volume<u8, Address<S>>> Ext2<S, V> impl<S: Size, V: Volume<u8, Address<S>>> Ext2<S, V>
where where
Error: From<V::Error>, Error: From<V::Error>,
{ {
@ -145,7 +145,7 @@ where
} }
} }
impl<S: Size + Copy, V: Volume<u8, Address<S>>> Ext2<S, V> { impl<S: Size, V: Volume<u8, Address<S>>> Ext2<S, V> {
fn superblock(&self) -> &Superblock { fn superblock(&self) -> &Superblock {
&self.superblock.inner &self.superblock.inner
} }
@ -224,8 +224,7 @@ pub struct Inodes<'a, S: 'a + Size, V: 'a + Volume<u8, Address<S>>> {
index: usize, index: usize,
} }
impl<'a, S: Size + Copy, V: 'a + Volume<u8, Address<S>>> Iterator impl<'a, S: Size, V: 'a + Volume<u8, Address<S>>> Iterator for Inodes<'a, S, V>
for Inodes<'a, S, V>
where where
Error: From<V::Error>, Error: From<V::Error>,
{ {
@ -261,7 +260,7 @@ pub struct Inode<'a, S: 'a + Size, V: 'a + Volume<u8, Address<S>>> {
inner: RawInode, inner: RawInode,
} }
impl<'a, S: 'a + Size + Copy, V: 'a + Volume<u8, Address<S>>> Inode<'a, S, V> { impl<'a, S: 'a + Size, V: 'a + Volume<u8, Address<S>>> Inode<'a, S, V> {
pub fn new(fs: &'a Ext2<S, V>, inner: RawInode) -> Inode<'a, S, V> { pub fn new(fs: &'a Ext2<S, V>, inner: RawInode) -> Inode<'a, S, V> {
Inode { fs, inner } Inode { fs, inner }
} }
@ -345,8 +344,7 @@ pub struct InodeBlocks<'a: 'b, 'b, S: 'a + Size, V: 'a + Volume<u8, Address<S>>>
index: usize, index: usize,
} }
impl<'a, 'b, S: Size + Copy, V: 'a + Volume<u8, Address<S>>> impl<'a, 'b, S: Size, V: 'a + Volume<u8, Address<S>>> InodeBlocks<'a, 'b, S, V>
InodeBlocks<'a, 'b, S, V>
where where
Error: From<V::Error>, Error: From<V::Error>,
{ {
@ -355,7 +353,7 @@ where
} }
} }
impl<'a, 'b, S: Size + Copy, V: 'a + Volume<u8, Address<S>>> Iterator impl<'a, 'b, S: Size, V: 'a + Volume<u8, Address<S>>> Iterator
for InodeBlocks<'a, 'b, S, V> for InodeBlocks<'a, 'b, S, V>
where where
Error: From<V::Error>, Error: From<V::Error>,

View file

@ -13,6 +13,7 @@ extern crate alloc;
extern crate bitflags; extern crate bitflags;
#[cfg(any(test, not(feature = "no_std")))] #[cfg(any(test, not(feature = "no_std")))]
extern crate core; extern crate core;
extern crate spin;
pub mod error; pub mod error;
pub mod sys; pub mod sys;

View file

@ -4,7 +4,7 @@ use core::ops::{Add, Sub};
use core::fmt::{self, Debug, Display, LowerHex}; use core::fmt::{self, Debug, Display, LowerHex};
use core::iter::Step; use core::iter::Step;
pub trait Size: PartialOrd { pub trait Size: Clone + Copy + PartialOrd {
// log_sector_size = log_2(sector_size) // log_sector_size = log_2(sector_size)
const LOG_SIZE: u32; const LOG_SIZE: u32;
const SIZE: usize = 1 << Self::LOG_SIZE; const SIZE: usize = 1 << Self::LOG_SIZE;
@ -96,7 +96,7 @@ impl<S: Size> Address<S> {
} }
} }
impl<S: Size + Clone + PartialOrd> Step for Address<S> { impl<S: Size> Step for Address<S> {
fn steps_between(start: &Self, end: &Self) -> Option<usize> { fn steps_between(start: &Self, end: &Self) -> Option<usize> {
if end.sector >= start.sector { if end.sector >= start.sector {
Some(end.sector as usize - start.sector as usize) Some(end.sector as usize - start.sector as usize)

View file

@ -52,10 +52,7 @@ impl Debug for BlockGroupDescriptor {
} }
impl BlockGroupDescriptor { impl BlockGroupDescriptor {
pub unsafe fn find_descriptor< pub unsafe fn find_descriptor<S: Size, V: Volume<u8, Address<S>>>(
S: Size + Copy + PartialOrd,
V: Volume<u8, Address<S>>,
>(
haystack: &V, haystack: &V,
offset: Address<S>, offset: Address<S>,
) -> Result<(BlockGroupDescriptor, Address<S>), Error> ) -> Result<(BlockGroupDescriptor, Address<S>), Error>
@ -79,10 +76,7 @@ impl BlockGroupDescriptor {
Ok(descr) Ok(descr)
} }
pub unsafe fn find_descriptor_table< pub unsafe fn find_descriptor_table<S: Size, V: Volume<u8, Address<S>>>(
S: Size + Copy + PartialOrd,
V: Volume<u8, Address<S>>,
>(
haystack: &V, haystack: &V,
offset: Address<S>, offset: Address<S>,
count: usize, count: usize,

View file

@ -97,10 +97,7 @@ impl Debug for Inode {
} }
impl Inode { impl Inode {
pub unsafe fn find_inode< pub unsafe fn find_inode<S: Size, V: Volume<u8, Address<S>>>(
S: Size + Copy + PartialOrd,
V: Volume<u8, Address<S>>,
>(
haystack: &V, haystack: &V,
offset: Address<S>, offset: Address<S>,
size: usize, size: usize,

View file

@ -195,7 +195,7 @@ impl Debug for Superblock {
} }
impl Superblock { impl Superblock {
pub unsafe fn find<S: Size + Copy + PartialOrd, V: Volume<u8, Address<S>>>( pub unsafe fn find<S: Size, V: Volume<u8, Address<S>>>(
haystack: &V, haystack: &V,
) -> Result<(Superblock, Address<S>), Error> ) -> Result<(Superblock, Address<S>), Error>
where where

View file

@ -227,7 +227,7 @@ impl<T, Idx> DerefMut for VolumeCommit<T, Idx> {
macro_rules! impl_slice { macro_rules! impl_slice {
(@inner $volume:ty $( , $lt:lifetime )* ) => { (@inner $volume:ty $( , $lt:lifetime )* ) => {
impl<$( $lt, )* S: Size + PartialOrd + Copy, T> Volume<T, Address<S>> impl<$( $lt, )* S: Size, T> Volume<T, Address<S>>
for $volume for $volume
where where
T: Clone, T: Clone,
@ -295,7 +295,7 @@ mod file {
use super::{Volume, VolumeCommit, VolumeSlice}; use super::{Volume, VolumeCommit, VolumeSlice};
use super::length::Length; use super::length::Length;
impl<S: Size + PartialOrd + Copy> Volume<u8, Address<S>> for RefCell<File> { impl<S: Size> Volume<u8, Address<S>> for RefCell<File> {
type Error = io::Error; type Error = io::Error;
fn size(&self) -> Length<Address<S>> { fn size(&self) -> Length<Address<S>> {