add constraints to `Size` trait

sync
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>,
}
impl<S: Size + Copy, V: Volume<u8, Address<S>>> Ext2<S, V>
impl<S: Size, V: Volume<u8, Address<S>>> Ext2<S, V>
where
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 {
&self.superblock.inner
}
@ -224,8 +224,7 @@ pub struct Inodes<'a, S: 'a + Size, V: 'a + Volume<u8, Address<S>>> {
index: usize,
}
impl<'a, S: Size + Copy, V: 'a + Volume<u8, Address<S>>> Iterator
for Inodes<'a, S, V>
impl<'a, S: Size, V: 'a + Volume<u8, Address<S>>> Iterator for Inodes<'a, S, V>
where
Error: From<V::Error>,
{
@ -261,7 +260,7 @@ pub struct Inode<'a, S: 'a + Size, V: 'a + Volume<u8, Address<S>>> {
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> {
Inode { fs, inner }
}
@ -345,8 +344,7 @@ pub struct InodeBlocks<'a: 'b, 'b, S: 'a + Size, V: 'a + Volume<u8, Address<S>>>
index: usize,
}
impl<'a, 'b, S: Size + Copy, V: 'a + Volume<u8, Address<S>>>
InodeBlocks<'a, 'b, S, V>
impl<'a, 'b, S: Size, V: 'a + Volume<u8, Address<S>>> InodeBlocks<'a, 'b, S, V>
where
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>
where
Error: From<V::Error>,

View File

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

View File

@ -4,7 +4,7 @@ use core::ops::{Add, Sub};
use core::fmt::{self, Debug, Display, LowerHex};
use core::iter::Step;
pub trait Size: PartialOrd {
pub trait Size: Clone + Copy + PartialOrd {
// log_sector_size = log_2(sector_size)
const LOG_SIZE: u32;
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> {
if end.sector >= start.sector {
Some(end.sector as usize - start.sector as usize)

View File

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

View File

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

View File

@ -195,7 +195,7 @@ impl Debug for 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,
) -> Result<(Superblock, Address<S>), Error>
where

View File

@ -227,7 +227,7 @@ impl<T, Idx> DerefMut for VolumeCommit<T, Idx> {
macro_rules! impl_slice {
(@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
where
T: Clone,
@ -295,7 +295,7 @@ mod file {
use super::{Volume, VolumeCommit, VolumeSlice};
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;
fn size(&self) -> Length<Address<S>> {