Skip to content

Commit

Permalink
Replace unsafe line with inlined function
Browse files Browse the repository at this point in the history
  • Loading branch information
dxrcy committed Oct 8, 2024
1 parent b1cc980 commit 9ed0b16
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/debugger/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,13 @@ impl Terminal {
write!(self.term, "\x1b[1;{}m", DEBUGGER_COLOR).unwrap();
write!(self.term, "Command: ").unwrap();
write!(self.term, "\x1b[0m").unwrap();
// This is necessary as cannot borrow `self.term` mutably and `self.get_current()` immutably
// TODO(safety/refactor): There must be a better way to do this
let current = unsafe { &*(self.get_current() as *const str) };

// Inline `self.get_current()` due to borrowing issues
let current = if self.is_next() {
&self.buffer
} else {
self.history.get(self.history_index).expect("checked above")
};
write!(self.term, "{}", current).unwrap();

self.term
Expand Down

0 comments on commit 9ed0b16

Please sign in to comment.