Skip to content
This repository has been archived by the owner on Jan 4, 2024. It is now read-only.

Commit

Permalink
i thought i could get away with it
Browse files Browse the repository at this point in the history
i was wrong :(
  • Loading branch information
Sky9x committed Nov 25, 2023
1 parent e560899 commit ec31266
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/dircheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn dir_check(dir: &Path, root: &NavFolder) -> Result<DirCheck> {

let mut nav_paths = HashSet::new();

root.for_each_page(|p| {
root.for_each_page(&mut |p| {
nav_paths.insert(&p.path);
});

Expand Down
4 changes: 2 additions & 2 deletions src/modes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn mode_check(root: &NavFolder) -> Result<()> {
let mut total = 0;
let mut fails = 0;

root.for_each_page(|page| {
root.for_each_page(&mut |page| {
total += 1;

// TODO rich diff?
Expand All @@ -47,7 +47,7 @@ pub fn mode_fix(root: &NavFolder) -> Result<()> {
let mut fixed = 0;
let mut total = 0;

root.try_for_each_page(|page| {
root.try_for_each_page(&mut |page| {
total += 1;

if page.fixed_content == page.raw_content {
Expand Down
19 changes: 8 additions & 11 deletions src/nav.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,37 +44,34 @@ pub enum NavItem {

impl NavItem {
#[allow(clippy::needless_lifetimes)] // ???
pub fn for_each_page<'s>(&'s self, mut f: impl FnMut(&'s NavPage)) {
pub fn for_each_page<'s>(&'s self, f: &mut impl FnMut(&'s NavPage)) {
match self {
NavItem::Page(x) => f(x),
NavItem::Folder(x) => x.for_each_page(f),
NavItem::Category(x) => x.children.iter().for_each(|i| i.for_each_page(&mut f)),
NavItem::Category(x) => x.children.iter().for_each(|i| i.for_each_page(f)),
}
}

pub fn try_for_each_page(&self, mut f: impl FnMut(&NavPage) -> Result<()>) -> Result<()> {
pub fn try_for_each_page(&self, f: &mut impl FnMut(&NavPage) -> Result<()>) -> Result<()> {
match self {
NavItem::Page(x) => f(x),
NavItem::Folder(x) => x.try_for_each_page(f),
NavItem::Category(x) => x
.children
.iter()
.try_for_each(|i| i.try_for_each_page(&mut f)),
NavItem::Category(x) => x.children.iter().try_for_each(|i| i.try_for_each_page(f)),
}
}
}

impl NavFolder {
#[allow(clippy::needless_lifetimes)] // ???
pub fn for_each_page<'s>(&'s self, mut f: impl FnMut(&'s NavPage)) {
pub fn for_each_page<'s>(&'s self, f: &mut impl FnMut(&'s NavPage)) {
f(&self.index);
self.children.iter().for_each(|i| i.for_each_page(&mut f));
self.children.iter().for_each(|i| i.for_each_page(f));
}

pub fn try_for_each_page(&self, mut f: impl FnMut(&NavPage) -> Result<()>) -> Result<()> {
pub fn try_for_each_page(&self, f: &mut impl FnMut(&NavPage) -> Result<()>) -> Result<()> {
f(&self.index)?;
self.children
.iter()
.try_for_each(|i| i.try_for_each_page(&mut f))
.try_for_each(|i| i.try_for_each_page(f))
}
}

0 comments on commit ec31266

Please sign in to comment.