file_model: Make index_of() return a u32

We only ever use it as a u32 elsewhere, so cut out
the casting.
This commit is contained in:
Christopher Davis 2022-06-29 16:58:11 -04:00
parent 70054971d9
commit 8c56e2c66a
2 changed files with 6 additions and 6 deletions

View file

@ -124,9 +124,9 @@ impl LpFileModel {
vec.get(index as usize).cloned() vec.get(index as usize).cloned()
} }
pub fn index_of(&self, file: &gio::File) -> Option<usize> { pub fn index_of(&self, file: &gio::File) -> Option<u32> {
let imp = self.imp(); let imp = self.imp();
let vec = imp.inner.borrow(); let vec = imp.inner.borrow();
vec.iter().position(|f| f.equal(file)) vec.iter().position(|f| f.equal(file)).map(|p| p as u32)
} }
} }

View file

@ -186,7 +186,7 @@ impl LpImageView {
} }
if let Some(model) = imp.model.borrow().as_ref() { if let Some(model) = imp.model.borrow().as_ref() {
let index = model.index_of(file).unwrap() as u32; let index = model.index_of(file).unwrap();
log::debug!("Currently at file {index} in the directory"); log::debug!("Currently at file {index} in the directory");
imp.filename.replace(util::get_file_display_name(file)); imp.filename.replace(util::get_file_display_name(file));
carousel.append(&LpImagePage::from_file(file)); carousel.append(&LpImagePage::from_file(file));
@ -220,8 +220,8 @@ impl LpImageView {
.current_page() .current_page()
.and_then(|p| p.file()) .and_then(|p| p.file())
.and_then(|f| model.index_of(&f)) .and_then(|f| model.index_of(&f))
.unwrap_or_default() as u32; .unwrap_or_default();
let new_index = model.index_of(file).unwrap_or_default() as u32; let new_index = model.index_of(file).unwrap_or_default();
// Code style note: I generally don't do early returns like this // Code style note: I generally don't do early returns like this
// in my rust code, but here we do it to avoid code duplication. // in my rust code, but here we do it to avoid code duplication.
@ -309,7 +309,7 @@ impl LpImageView {
let model = b.as_ref().unwrap(); let model = b.as_ref().unwrap();
let current = self.current_page().and_then(|p| p.file()).unwrap(); let current = self.current_page().and_then(|p| p.file()).unwrap();
let model_index = model.index_of(&current).unwrap() as u32; let model_index = model.index_of(&current).unwrap();
let prev_index = imp.prev_index.get(); let prev_index = imp.prev_index.get();
if model_index != prev_index { if model_index != prev_index {