Simplify code by using Self in return type

This commit is contained in:
Rafał Harabień 2018-06-06 17:16:32 +02:00
parent 75a6c32360
commit 1656540eac
4 changed files with 8 additions and 9 deletions

View File

@ -87,7 +87,7 @@ pub struct Dir<'a, 'b: 'a> {
} }
impl <'a, 'b> Dir<'a, 'b> { impl <'a, 'b> Dir<'a, 'b> {
pub(crate) fn new(stream: DirRawStream<'a, 'b>, fs: FileSystemRef<'a, 'b>) -> Dir<'a, 'b> { pub(crate) fn new(stream: DirRawStream<'a, 'b>, fs: FileSystemRef<'a, 'b>) -> Self {
Dir { stream, fs } Dir { stream, fs }
} }
@ -115,7 +115,7 @@ impl <'a, 'b> Dir<'a, 'b> {
} }
/// Opens existing directory /// Opens existing directory
pub fn open_dir(&mut self, path: &str) -> io::Result<Dir<'a, 'b>> { pub fn open_dir(&mut self, path: &str) -> io::Result<Self> {
let (name, rest_opt) = split_path(path); let (name, rest_opt) = split_path(path);
let e = self.find_entry(name, None)?; let e = self.find_entry(name, None)?;
match rest_opt { match rest_opt {
@ -158,7 +158,7 @@ impl <'a, 'b> Dir<'a, 'b> {
} }
/// Creates new directory or opens existing. /// Creates new directory or opens existing.
pub fn create_dir(&mut self, path: &str) -> io::Result<Dir<'a, 'b>> { pub fn create_dir(&mut self, path: &str) -> io::Result<Self> {
let (name, rest_opt) = split_path(path); let (name, rest_opt) = split_path(path);
match rest_opt { match rest_opt {
// path contains more than 1 component // path contains more than 1 component
@ -499,7 +499,7 @@ struct LongNameBuilder {
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
impl LongNameBuilder { impl LongNameBuilder {
fn new() -> LongNameBuilder { fn new() -> Self {
LongNameBuilder { LongNameBuilder {
buf: Vec::<u16>::new(), buf: Vec::<u16>::new(),
chksum: 0, chksum: 0,

View File

@ -357,7 +357,7 @@ impl DirEntryData {
} }
} }
pub(crate) fn deserialize(rdr: &mut Read) -> io::Result<DirEntryData> { pub(crate) fn deserialize(rdr: &mut Read) -> io::Result<Self> {
let mut name = [0; 11]; let mut name = [0; 11];
match rdr.read_exact(&mut name) { match rdr.read_exact(&mut name) {
Err(ref err) if err.kind() == io::ErrorKind::UnexpectedEof => { Err(ref err) if err.kind() == io::ErrorKind::UnexpectedEof => {
@ -531,7 +531,7 @@ pub(crate) struct DirEntryEditor {
} }
impl DirEntryEditor { impl DirEntryEditor {
fn new(data: DirFileEntryData, pos: u64) -> DirEntryEditor { fn new(data: DirFileEntryData, pos: u64) -> Self {
DirEntryEditor { DirEntryEditor {
data, pos, data, pos,
dirty: false, dirty: false,

View File

@ -365,7 +365,7 @@ impl <'a> FileSystem<'a> {
/// ///
/// Note: creating multiple filesystem objects with one underlying device/disk image can /// Note: creating multiple filesystem objects with one underlying device/disk image can
/// cause filesystem corruption. /// cause filesystem corruption.
pub fn new<T: ReadWriteSeek>(disk: &'a mut T, options: FsOptions) -> io::Result<FileSystem<'a>> { pub fn new<T: ReadWriteSeek>(disk: &'a mut T, options: FsOptions) -> io::Result<Self> {
// Make sure given image is not seeked // Make sure given image is not seeked
debug_assert!(disk.seek(SeekFrom::Current(0))? == 0); debug_assert!(disk.seek(SeekFrom::Current(0))? == 0);

View File

@ -334,8 +334,7 @@ pub(crate) struct ClusterIterator<'a, 'b: 'a> {
} }
impl <'a, 'b> ClusterIterator<'a, 'b> { impl <'a, 'b> ClusterIterator<'a, 'b> {
pub(crate) fn new(fat: DiskSlice<'a, 'b>, fat_type: FatType, cluster: u32) pub(crate) fn new(fat: DiskSlice<'a, 'b>, fat_type: FatType, cluster: u32) -> Self {
-> ClusterIterator<'a, 'b> {
ClusterIterator { ClusterIterator {
fat, fat,
fat_type, fat_type,