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> {
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 }
}
@ -115,7 +115,7 @@ impl <'a, 'b> Dir<'a, 'b> {
}
/// 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 e = self.find_entry(name, None)?;
match rest_opt {
@ -158,7 +158,7 @@ impl <'a, 'b> Dir<'a, 'b> {
}
/// 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);
match rest_opt {
// path contains more than 1 component
@ -499,7 +499,7 @@ struct LongNameBuilder {
#[cfg(feature = "alloc")]
impl LongNameBuilder {
fn new() -> LongNameBuilder {
fn new() -> Self {
LongNameBuilder {
buf: Vec::<u16>::new(),
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];
match rdr.read_exact(&mut name) {
Err(ref err) if err.kind() == io::ErrorKind::UnexpectedEof => {
@ -531,7 +531,7 @@ pub(crate) struct DirEntryEditor {
}
impl DirEntryEditor {
fn new(data: DirFileEntryData, pos: u64) -> DirEntryEditor {
fn new(data: DirFileEntryData, pos: u64) -> Self {
DirEntryEditor {
data, pos,
dirty: false,

View File

@ -365,7 +365,7 @@ impl <'a> FileSystem<'a> {
///
/// Note: creating multiple filesystem objects with one underlying device/disk image can
/// 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
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> {
pub(crate) fn new(fat: DiskSlice<'a, 'b>, fat_type: FatType, cluster: u32)
-> ClusterIterator<'a, 'b> {
pub(crate) fn new(fat: DiskSlice<'a, 'b>, fat_type: FatType, cluster: u32) -> Self {
ClusterIterator {
fat,
fat_type,