Skip to content

Commit 2efc39a

Browse files
src: increase use of Self where possible
Various bits of code here predate my having learned what Self. We're about to throw a bunch of generic type arguments absolutely everywhere, so increase our use of Self first to help make that less painful. Signed-off-by: Allison Karlitskaya <[email protected]>
1 parent e784d57 commit 2efc39a

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

src/fs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl FilesystemReader<'_> {
176176
st_uid: buf.st_uid,
177177
st_gid: buf.st_gid,
178178
st_mtim_sec: buf.st_mtime as i64,
179-
xattrs: RefCell::new(FilesystemReader::read_xattrs(fd)?),
179+
xattrs: RefCell::new(Self::read_xattrs(fd)?),
180180
},
181181
))
182182
}
@@ -225,7 +225,7 @@ impl FilesystemReader<'_> {
225225
Mode::empty(),
226226
)?;
227227

228-
let (buf, stat) = FilesystemReader::stat(&fd, ifmt)?;
228+
let (buf, stat) = Self::stat(&fd, ifmt)?;
229229

230230
// NB: We could check `st_nlink > 1` to find out if we should track a file as a potential
231231
// hardlink or not, but some filesystems (like fuse-overlayfs) can report this incorrectly.
@@ -249,7 +249,7 @@ impl FilesystemReader<'_> {
249249
Mode::empty(),
250250
)?;
251251

252-
let (_, stat) = FilesystemReader::stat(&fd, FileType::Directory)?;
252+
let (_, stat) = Self::stat(&fd, FileType::Directory)?;
253253
let mut directory = Directory::new(stat);
254254

255255
for item in Dir::read_from(&fd)? {

src/repository.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl Repository {
4646
)
4747
}
4848

49-
pub fn open_path(dirfd: impl AsFd, path: impl AsRef<Path>) -> Result<Repository> {
49+
pub fn open_path(dirfd: impl AsFd, path: impl AsRef<Path>) -> Result<Self> {
5050
let path = path.as_ref();
5151

5252
// O_PATH isn't enough because flock()
@@ -56,17 +56,17 @@ impl Repository {
5656
flock(&repository, FlockOperation::LockShared)
5757
.context("Cannot lock composefs repository")?;
5858

59-
Ok(Repository { repository })
59+
Ok(Self { repository })
6060
}
6161

62-
pub fn open_user() -> Result<Repository> {
62+
pub fn open_user() -> Result<Self> {
6363
let home = std::env::var("HOME").with_context(|| "$HOME must be set when in user mode")?;
6464

65-
Repository::open_path(CWD, PathBuf::from(home).join(".var/lib/composefs"))
65+
Self::open_path(CWD, PathBuf::from(home).join(".var/lib/composefs"))
6666
}
6767

68-
pub fn open_system() -> Result<Repository> {
69-
Repository::open_path(CWD, PathBuf::from("/sysroot/composefs".to_string()))
68+
pub fn open_system() -> Result<Self> {
69+
Self::open_path(CWD, PathBuf::from("/sysroot/composefs".to_string()))
7070
}
7171

7272
fn ensure_dir(&self, dir: impl AsRef<Path>) -> ErrnoResult<()> {
@@ -212,7 +212,7 @@ impl Repository {
212212
};
213213
let stream_path = format!("streams/{}", hex::encode(sha256));
214214
let object_id = writer.done()?;
215-
let object_path = Repository::format_object_path(&object_id);
215+
let object_path = Self::format_object_path(&object_id);
216216
self.ensure_symlink(&stream_path, &object_path)?;
217217

218218
if let Some(name) = reference {
@@ -261,7 +261,7 @@ impl Repository {
261261
callback(&mut writer)?;
262262
let object_id = writer.done()?;
263263

264-
let object_path = Repository::format_object_path(&object_id);
264+
let object_path = Self::format_object_path(&object_id);
265265
self.ensure_symlink(&stream_path, &object_path)?;
266266
object_id
267267
}
@@ -411,11 +411,11 @@ impl Repository {
411411
let filename = entry.file_name();
412412
if filename != c"." && filename != c".." {
413413
let dirfd = openat(&fd, filename, OFlags::RDONLY, Mode::empty())?;
414-
Repository::walk_symlinkdir(dirfd, objects)?;
414+
Self::walk_symlinkdir(dirfd, objects)?;
415415
}
416416
}
417417
FileType::Symlink => {
418-
objects.insert(Repository::read_symlink_hashvalue(&fd, entry.file_name())?);
418+
objects.insert(Self::read_symlink_hashvalue(&fd, entry.file_name())?);
419419
}
420420
_ => {
421421
bail!("Unexpected file type encountered");
@@ -447,7 +447,7 @@ impl Repository {
447447
OFlags::RDONLY | OFlags::DIRECTORY,
448448
Mode::empty(),
449449
)?;
450-
Repository::walk_symlinkdir(refs, &mut objects)?;
450+
Self::walk_symlinkdir(refs, &mut objects)?;
451451

452452
for item in Dir::read_from(&category_fd)? {
453453
let entry = item?;

src/splitstream.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ impl std::fmt::Debug for SplitStreamWriter<'_> {
7878
}
7979
}
8080

81-
impl SplitStreamWriter<'_> {
81+
impl<'a> SplitStreamWriter<'a> {
8282
pub fn new(
83-
repo: &Repository,
83+
repo: &'a Repository,
8484
refs: Option<DigestMap>,
8585
sha256: Option<Sha256Digest>,
86-
) -> SplitStreamWriter {
86+
) -> Self {
8787
// SAFETY: we surely can't get an error writing the header to a Vec<u8>
8888
let mut writer = Encoder::new(vec![], 0).unwrap();
8989

@@ -97,7 +97,7 @@ impl SplitStreamWriter<'_> {
9797
}
9898
}
9999

100-
SplitStreamWriter {
100+
Self {
101101
repo,
102102
inline_content: vec![],
103103
writer,
@@ -113,7 +113,7 @@ impl SplitStreamWriter<'_> {
113113
/// flush any buffered inline data, taking new_value as the new value of the buffer
114114
fn flush_inline(&mut self, new_value: Vec<u8>) -> Result<()> {
115115
if !self.inline_content.is_empty() {
116-
SplitStreamWriter::write_fragment(
116+
Self::write_fragment(
117117
&mut self.writer,
118118
self.inline_content.len(),
119119
&self.inline_content,
@@ -140,7 +140,7 @@ impl SplitStreamWriter<'_> {
140140
// external data becomes the start of a new inline block.
141141
self.flush_inline(padding)?;
142142

143-
SplitStreamWriter::write_fragment(&mut self.writer, 0, reference.as_bytes())
143+
Self::write_fragment(&mut self.writer, 0, reference.as_bytes())
144144
}
145145

146146
pub fn write_external(&mut self, data: &[u8], padding: Vec<u8>) -> Result<()> {
@@ -214,7 +214,7 @@ enum ChunkType {
214214
}
215215

216216
impl<R: Read> SplitStreamReader<R> {
217-
pub fn new(reader: R) -> Result<SplitStreamReader<R>> {
217+
pub fn new(reader: R) -> Result<Self> {
218218
let mut decoder = Decoder::new(reader)?;
219219

220220
let n_map_entries = {
@@ -230,7 +230,7 @@ impl<R: Read> SplitStreamReader<R> {
230230
refs.map.push(DigestMapEntry::read_from_io(&mut decoder)?);
231231
}
232232

233-
Ok(SplitStreamReader {
233+
Ok(Self {
234234
decoder,
235235
refs,
236236
inline_bytes: 0,

0 commit comments

Comments
 (0)