From 934266ca4b894d37c3ade52d1e50576c33e2b40e Mon Sep 17 00:00:00 2001 From: Szymon Walter Date: Wed, 21 Mar 2018 18:54:50 +0100 Subject: [PATCH] add constraints to `Size` trait --- src/fs.rs | 14 ++++++-------- src/lib.rs | 1 + src/sector.rs | 4 ++-- src/sys/block_group.rs | 10 ++-------- src/sys/inode.rs | 5 +---- src/sys/superblock.rs | 2 +- src/volume/mod.rs | 4 ++-- 7 files changed, 15 insertions(+), 25 deletions(-) diff --git a/src/fs.rs b/src/fs.rs index 385765a..be333db 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -30,7 +30,7 @@ pub struct Ext2>> { block_groups: Struct, S>, } -impl>> Ext2 +impl>> Ext2 where Error: From, { @@ -145,7 +145,7 @@ where } } -impl>> Ext2 { +impl>> Ext2 { fn superblock(&self) -> &Superblock { &self.superblock.inner } @@ -224,8 +224,7 @@ pub struct Inodes<'a, S: 'a + Size, V: 'a + Volume>> { index: usize, } -impl<'a, S: Size + Copy, V: 'a + Volume>> Iterator - for Inodes<'a, S, V> +impl<'a, S: Size, V: 'a + Volume>> Iterator for Inodes<'a, S, V> where Error: From, { @@ -261,7 +260,7 @@ pub struct Inode<'a, S: 'a + Size, V: 'a + Volume>> { inner: RawInode, } -impl<'a, S: 'a + Size + Copy, V: 'a + Volume>> Inode<'a, S, V> { +impl<'a, S: 'a + Size, V: 'a + Volume>> Inode<'a, S, V> { pub fn new(fs: &'a Ext2, 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>> index: usize, } -impl<'a, 'b, S: Size + Copy, V: 'a + Volume>> - InodeBlocks<'a, 'b, S, V> +impl<'a, 'b, S: Size, V: 'a + Volume>> InodeBlocks<'a, 'b, S, V> where Error: From, { @@ -355,7 +353,7 @@ where } } -impl<'a, 'b, S: Size + Copy, V: 'a + Volume>> Iterator +impl<'a, 'b, S: Size, V: 'a + Volume>> Iterator for InodeBlocks<'a, 'b, S, V> where Error: From, diff --git a/src/lib.rs b/src/lib.rs index 59a6381..1e36af7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; diff --git a/src/sector.rs b/src/sector.rs index de229fd..2d24b02 100644 --- a/src/sector.rs +++ b/src/sector.rs @@ -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 Address { } } -impl Step for Address { +impl Step for Address { fn steps_between(start: &Self, end: &Self) -> Option { if end.sector >= start.sector { Some(end.sector as usize - start.sector as usize) diff --git a/src/sys/block_group.rs b/src/sys/block_group.rs index 5a713d8..b280aeb 100644 --- a/src/sys/block_group.rs +++ b/src/sys/block_group.rs @@ -52,10 +52,7 @@ impl Debug for BlockGroupDescriptor { } impl BlockGroupDescriptor { - pub unsafe fn find_descriptor< - S: Size + Copy + PartialOrd, - V: Volume>, - >( + pub unsafe fn find_descriptor>>( haystack: &V, offset: Address, ) -> Result<(BlockGroupDescriptor, Address), Error> @@ -79,10 +76,7 @@ impl BlockGroupDescriptor { Ok(descr) } - pub unsafe fn find_descriptor_table< - S: Size + Copy + PartialOrd, - V: Volume>, - >( + pub unsafe fn find_descriptor_table>>( haystack: &V, offset: Address, count: usize, diff --git a/src/sys/inode.rs b/src/sys/inode.rs index a969fef..f391cbf 100644 --- a/src/sys/inode.rs +++ b/src/sys/inode.rs @@ -97,10 +97,7 @@ impl Debug for Inode { } impl Inode { - pub unsafe fn find_inode< - S: Size + Copy + PartialOrd, - V: Volume>, - >( + pub unsafe fn find_inode>>( haystack: &V, offset: Address, size: usize, diff --git a/src/sys/superblock.rs b/src/sys/superblock.rs index 2ad9cc6..917d705 100644 --- a/src/sys/superblock.rs +++ b/src/sys/superblock.rs @@ -195,7 +195,7 @@ impl Debug for Superblock { } impl Superblock { - pub unsafe fn find>>( + pub unsafe fn find>>( haystack: &V, ) -> Result<(Superblock, Address), Error> where diff --git a/src/volume/mod.rs b/src/volume/mod.rs index 054dd37..fa427b0 100644 --- a/src/volume/mod.rs +++ b/src/volume/mod.rs @@ -227,7 +227,7 @@ impl DerefMut for VolumeCommit { macro_rules! impl_slice { (@inner $volume:ty $( , $lt:lifetime )* ) => { - impl<$( $lt, )* S: Size + PartialOrd + Copy, T> Volume> + impl<$( $lt, )* S: Size, T> Volume> for $volume where T: Clone, @@ -295,7 +295,7 @@ mod file { use super::{Volume, VolumeCommit, VolumeSlice}; use super::length::Length; - impl Volume> for RefCell { + impl Volume> for RefCell { type Error = io::Error; fn size(&self) -> Length> {