Skip to content

Commit 5072853

Browse files
committed
clippy fixes
Signed-off-by: Brian L. Troutwine <[email protected]>
1 parent 2ac517b commit 5072853

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

lading/src/generator/file_gen/model.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -100,21 +100,29 @@ impl File {
100100
}
101101

102102
/// Close a handle to this file.
103+
///
104+
/// # Panics
105+
///
106+
/// Function will panic if attempt is made to close file with no file
107+
/// handles outstanding.
103108
pub fn close(&mut self, now: Tick) {
104109
self.advance_time(now);
105110

106-
if self.open_handles == 0 {
107-
panic!("Attempted to close a file with no open handles");
108-
}
111+
assert!(
112+
self.open_handles == 0,
113+
"Attempted to close a file with no open handles"
114+
);
109115
self.open_handles -= 1;
110116
}
111117

112118
/// Return the number of open file handles to this `File`
119+
#[must_use]
113120
pub fn open_handles(&self) -> usize {
114121
self.open_handles
115122
}
116123

117124
/// Return whether the file is unlinked or not
125+
#[must_use]
118126
pub fn unlinked(&self) -> bool {
119127
self.unlinked
120128
}
@@ -463,7 +471,7 @@ impl State {
463471
file.open(now);
464472
let id = self.next_file_handle;
465473
self.next_file_handle = self.next_file_handle.wrapping_add(1);
466-
Some(FileHandle { inode, id })
474+
Some(FileHandle { id, inode })
467475
} else {
468476
None
469477
}
@@ -472,11 +480,15 @@ impl State {
472480
/// Close a file handle.
473481
///
474482
/// This function advances time.
483+
///
484+
/// # Panics
485+
///
486+
/// Function will panic if `FileHandle` is not valid.
475487
pub fn close_file(&mut self, now: Tick, handle: FileHandle) {
476488
self.advance_time(now);
477489

478490
if let Some(Node::File { file, .. }) = self.nodes.get_mut(&handle.inode) {
479-
file.close(now)
491+
file.close(now);
480492
} else {
481493
panic!("Invalid file handle");
482494
}
@@ -489,16 +501,6 @@ impl State {
489501
/// Will panic if passed `now` is less than recorded `now`. Time can only
490502
/// advance.
491503
pub fn advance_time(&mut self, now: Tick) {
492-
// Okay so here's the idea.
493-
//
494-
// 1. I introduce a read-only File via boolean flag
495-
// 2. A File has a "peer" Option<Inode> that allows for lookup of the next in line
496-
// 3. The names are held here. We traverse the linked list of peers and
497-
// then delete anything past max_rotations.
498-
//
499-
// The State holds all notion of when a File should rotate and also be
500-
// deleted. The File has no say in that at all.
501-
502504
assert!(now >= self.now);
503505
let mut inodes: Vec<Inode> = self.nodes.keys().copied().collect();
504506

@@ -611,8 +613,7 @@ impl State {
611613
file.incr_ordinal();
612614

613615
let remove_current = file.ordinal() > self.max_rotations;
614-
let next_peer = file.peer;
615-
(remove_current, next_peer)
616+
(remove_current, file.peer)
616617
}
617618
Node::Directory { .. } => panic!("Expected a File node"),
618619
}

0 commit comments

Comments
 (0)