stop using any nightly features (ill miss u const traits)

This commit is contained in:
alice pellerin
2026-05-01 00:41:37 -05:00
parent 7eb8c84c6e
commit 35a01b9128
7 changed files with 37 additions and 28 deletions
+1 -2
View File
@@ -1,9 +1,8 @@
use core::slice::GetDisjointMutIndex;
use std::{collections::HashSet, fs::File, io::{self, Read}, path::PathBuf}; use std::{collections::HashSet, fs::File, io::{self, Read}, path::PathBuf};
use crossterm::event::KeyEvent; use crossterm::event::KeyEvent;
use ratatui::{style::Stylize, text::Span}; use ratatui::{style::Stylize, text::Span};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::{BYTES_PER_LINE, action::{Action, AppAction}, buffer::actions::bytes_to_nat, config::Config, cursor::Cursor, edit_action::EditAction, popup::Popup, window_size::WindowSize}; use crate::{BYTES_PER_LINE, action::{Action, AppAction}, buffer::actions::bytes_to_nat, config::Config, cursor::Cursor, edit_action::EditAction, popup::Popup, utilities::IsOverlapping, window_size::WindowSize};
mod widget; mod widget;
mod actions; mod actions;
+14 -12
View File
@@ -1,4 +1,4 @@
use std::{cmp::min, collections::hash_set::Entry, convert::identity, fs::File, io::Write, iter, mem::{replace, swap}}; use std::{cmp::min, convert::identity, fs::File, io::Write, iter, mem::{replace, swap}};
use itertools::Itertools; use itertools::Itertools;
use ratatui::{style::{Color, Stylize}, text::Span}; use ratatui::{style::{Color, Stylize}, text::Span};
use crate::{BYTES_OF_PADDING, BYTES_PER_LINE, LINES_OF_PADDING, action::BufferAction, buffer::{Buffer, InspectionStatus, Mode, PartialAction}, cursor::Cursor, edit_action::EditAction, popup::Popup, utilities::{Floorable, SaturatingSubtract}, window_size::WindowSize}; use crate::{BYTES_OF_PADDING, BYTES_PER_LINE, LINES_OF_PADDING, action::BufferAction, buffer::{Buffer, InspectionStatus, Mode, PartialAction}, cursor::Cursor, edit_action::EditAction, popup::Popup, utilities::{Floorable, SaturatingSubtract}, window_size::WindowSize};
@@ -467,20 +467,18 @@ impl Buffer {
} }
fn toggle_mark(&mut self) { fn toggle_mark(&mut self) {
match self.marks.entry(self.primary_cursor.lower_bound()) { if !self.marks.insert(self.primary_cursor.lower_bound()) {
Entry::Occupied(occupied_entry) => { occupied_entry.remove(); }, self.marks.remove(&self.primary_cursor.lower_bound());
Entry::Vacant(vacant_entry) => vacant_entry.insert(),
} }
for cursor in &self.cursors { for cursor in &self.cursors {
match self.marks.entry(cursor.lower_bound()) { if !self.marks.insert(cursor.lower_bound()) {
Entry::Occupied(occupied_entry) => { occupied_entry.remove(); }, self.marks.remove(&cursor.lower_bound());
Entry::Vacant(vacant_entry) => vacant_entry.insert(),
} }
} }
} }
const fn align_view_center(&mut self, window_size: WindowSize) { fn align_view_center(&mut self, window_size: WindowSize) {
let half_a_screen = window_size.visible_byte_count() / 2; let half_a_screen = window_size.visible_byte_count() / 2;
self.scroll_position = self.primary_cursor.head self.scroll_position = self.primary_cursor.head
@@ -499,7 +497,7 @@ impl Buffer {
.min(self.max_contents_index().floored_to_the_nearest(BYTES_PER_LINE)); .min(self.max_contents_index().floored_to_the_nearest(BYTES_PER_LINE));
} }
const fn align_view_top(&mut self, window_size: WindowSize) { fn align_view_top(&mut self, window_size: WindowSize) {
self.scroll_position = self.primary_cursor.head self.scroll_position = self.primary_cursor.head
.floored_to_the_nearest(BYTES_PER_LINE) .floored_to_the_nearest(BYTES_PER_LINE)
.saturating_sub(self.top_padding(window_size)); .saturating_sub(self.top_padding(window_size));
@@ -676,7 +674,7 @@ fn inspect(selection: &[u8]) -> Vec<Span<'static>> {
let utf8 = str::from_utf8(selection).ok() let utf8 = str::from_utf8(selection).ok()
.filter(|_| selection.len() != 1) .filter(|_| selection.len() != 1)
.map(|utf8| utf8.trim_suffix('\0')) .map(|utf8| utf8.trim_end_matches('\0'))
.filter(|utf8| !utf8.contains(is_illegal_control_character)) .filter(|utf8| !utf8.contains(is_illegal_control_character))
.map(|utf8| Span::from(format!("\"{utf8}\"")).red()); .map(|utf8| Span::from(format!("\"{utf8}\"")).red());
@@ -830,7 +828,7 @@ impl Buffer {
} }
} }
pub const fn clamp_screen_to_contents(&mut self, window_size: WindowSize) { pub fn clamp_screen_to_contents(&mut self, window_size: WindowSize) {
let max_scroll_position = self.max_contents_index() let max_scroll_position = self.max_contents_index()
.floored_to_the_nearest(BYTES_PER_LINE) .floored_to_the_nearest(BYTES_PER_LINE)
.saturating_sub(Self::bottom_padding(window_size)); .saturating_sub(Self::bottom_padding(window_size));
@@ -868,7 +866,11 @@ pub fn bytes_to_nat(bytes: &[u8]) -> Option<u64> {
.rev() // little-endian .rev() // little-endian
.skip_while(|&&byte| byte == 0) .skip_while(|&&byte| byte == 0)
.try_fold(u64::default(), |result, &byte| { .try_fold(u64::default(), |result, &byte| {
Some(result.shl_exact(8)? | u64::from(byte)) if result.leading_zeros() < 8 {
None
} else {
Some((result << 8) | u64::from(byte))
}
}) })
} }
+7 -7
View File
@@ -93,7 +93,7 @@ impl Cursor {
} }
} }
pub const fn goto_line_start(&mut self) { pub fn goto_line_start(&mut self) {
self.extend_line_start(); self.extend_line_start();
self.collapse(); self.collapse();
} }
@@ -108,12 +108,12 @@ impl Cursor {
self.collapse(); self.collapse();
} }
pub const fn goto_file_end(&mut self, max: usize) { pub fn goto_file_end(&mut self, max: usize) {
self.extend_file_end(max); self.extend_file_end(max);
self.collapse(); self.collapse();
} }
pub const fn extend_line_start(&mut self) { pub fn extend_line_start(&mut self) {
self.head.floor_to_the_nearest(BYTES_PER_LINE); self.head.floor_to_the_nearest(BYTES_PER_LINE);
} }
@@ -128,7 +128,7 @@ impl Cursor {
self.head %= BYTES_PER_LINE; self.head %= BYTES_PER_LINE;
} }
pub const fn extend_file_end(&mut self, max: usize) { pub fn extend_file_end(&mut self, max: usize) {
self.head += previous_multiple_of(BYTES_PER_LINE, max + 1 - self.head); self.head += previous_multiple_of(BYTES_PER_LINE, max + 1 - self.head);
} }
@@ -156,7 +156,7 @@ impl Cursor {
} }
} }
pub const fn move_previous_word_start(&mut self) { pub fn move_previous_word_start(&mut self) {
if self.head == 0 { return; } if self.head == 0 { return; }
self.collapse(); self.collapse();
@@ -188,7 +188,7 @@ impl Cursor {
} }
} }
pub const fn extend_previous_word_start(&mut self) { pub fn extend_previous_word_start(&mut self) {
if self.head == 0 { return; } if self.head == 0 { return; }
if self.head.is_multiple_of(4) { // at the beginning of a word if self.head.is_multiple_of(4) { // at the beginning of a word
@@ -236,7 +236,7 @@ impl Cursor {
} }
} }
const fn previous_multiple_of(multiple: usize, number: usize) -> usize { fn previous_multiple_of(multiple: usize, number: usize) -> usize {
number.saturating_sub(1).floored_to_the_nearest(multiple) number.saturating_sub(1).floored_to_the_nearest(multiple)
} }
-5
View File
@@ -1,11 +1,6 @@
#![warn(clippy::pedantic, clippy::nursery)] #![warn(clippy::pedantic, clippy::nursery)]
#![allow(clippy::cast_possible_truncation)] #![allow(clippy::cast_possible_truncation)]
#![allow(clippy::enum_glob_use)] #![allow(clippy::enum_glob_use)]
#![feature(get_disjoint_mut_helpers)]
#![feature(exact_bitshifts)]
#![feature(hash_set_entry)]
#![feature(trim_prefix_suffix)]
#![feature(const_trait_impl)]
use arguments::Arguments; use arguments::Arguments;
use clap::Parser; use clap::Parser;
+2
View File
@@ -3,9 +3,11 @@ mod empty_span;
mod custom_greys; mod custom_greys;
mod floor_to_the_nearest; mod floor_to_the_nearest;
mod saturating_subtract; mod saturating_subtract;
mod is_overlapping;
pub use cardinality::HasCardinality; pub use cardinality::HasCardinality;
pub use empty_span::empty_span; pub use empty_span::empty_span;
pub use custom_greys::CustomGreys; pub use custom_greys::CustomGreys;
pub use floor_to_the_nearest::Floorable; pub use floor_to_the_nearest::Floorable;
pub use saturating_subtract::SaturatingSubtract; pub use saturating_subtract::SaturatingSubtract;
pub use is_overlapping::IsOverlapping;
+2 -2
View File
@@ -1,10 +1,10 @@
pub const trait Floorable { pub trait Floorable {
fn floor_to_the_nearest(&mut self, step: Self); fn floor_to_the_nearest(&mut self, step: Self);
fn floored_to_the_nearest(self, step: Self) -> Self; fn floored_to_the_nearest(self, step: Self) -> Self;
} }
const impl Floorable for usize { impl Floorable for usize {
fn floor_to_the_nearest(&mut self, step: Self) { fn floor_to_the_nearest(&mut self, step: Self) {
*self -= *self % step; *self -= *self % step;
} }
+11
View File
@@ -0,0 +1,11 @@
use std::ops::RangeInclusive;
pub trait IsOverlapping {
fn is_overlapping(&self, other: &Self) -> bool;
}
impl IsOverlapping for RangeInclusive<usize> {
fn is_overlapping(&self, other: &Self) -> bool {
self.contains(other.start()) || self.contains(other.end())
}
}