Error[0502] Got some mutabilities and immutabilities problems in function argument of Git Explorer

Hello Everybody!

I am building a side project called Git Explorer, I want to use TUI to draw a terminal user interface that makes use of beautiful UTF-8 chars to draw a beautiful git graph of the current repository.

Right now I have a "Home screen" that draws the git graph (it has some errors but a least it looks beautiful) and shows the diff with colors (the diff with colors has some errors, but at least it shows colors :smiley: ). Now I want to build a feature to collapse branches: if you have a commit that has 2 parents, then you can select it, hit the space bar, and it will collapse all commits until reaching the common ancestor.

This screenshot explains what I'd like to do, take a look at the issue #2 in the github repo for more details about it.

Prior doing this, I decided to refactor the code to simplify the function that generates the graphemes to build the graph. When I reached a simple refactoring task: move arguments of the method into attributes of the struct, I stumbled upon a problem that is driving me nuts.

In order to make this refactorization, I --needed-- to make the function that generates the grapheme to take a mutable reference to self. This single line change escalated to another part of the struct, and I don't know how to solve the problem

PR #3 shows my first attempt to solve the problem (I put there some comments on the code), and PR #6 shows the minimum 2 line changes you need to do to reproduce the problem. All the PR of the project are related to this issue. You can take a look at them to see what else I attempted to do, but these 2 PR are the most important ones.

NOTE I am using 2 unstable features of Rust, so make sure you are using a nightly build of Rust to compile the project. These are the unstable features located at the beginning of the src/main.rs file. I am using v1.70.0-nightly rust version (rustc 1.70.0-nightly (7820b62d2 2023-03-05))

#![feature(iter_collect_into)]
#![feature(slice_partition_dedup)]

Thanks for your attention,

Best