Use stable rust

This commit is contained in:
Andras Schmelczer 2026-03-11 21:07:23 +00:00
parent 31993762de
commit c2144a2634
18 changed files with 118 additions and 44 deletions

View file

@ -331,7 +331,7 @@ where
order: last_equal_order,
length: last_equal_length,
#[cfg(debug_assertions)]
text: last_equal_text,
text: last_equal_text,
..
}),
) => {
@ -342,7 +342,8 @@ where
// matching (order, length) means they cover the same substring
#[cfg(debug_assertions)]
debug_assert_eq!(
text, last_equal_text,
text,
last_equal_text,
"Equal operations with same order and length should have the same text, \
but got {operation:?} vs {:?}",
Operation::<T>::Equal {
@ -438,7 +439,9 @@ impl<T> Debug for Operation<T>
where
T: PartialEq + Clone + Debug,
{
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "{self}") }
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{self}")
}
}
#[cfg(test)]

View file

@ -20,7 +20,9 @@ impl<T> RawOperation<T>
where
T: PartialEq + Clone + Debug,
{
pub fn vec_from(left: &[Token<T>], right: &[Token<T>]) -> Vec<Self> { myers_diff(left, right) }
pub fn vec_from(left: &[Token<T>], right: &[Token<T>]) -> Vec<Self> {
myers_diff(left, right)
}
pub fn tokens(&self) -> &[Token<T>] {
match self {

View file

@ -1,6 +1,5 @@
---
source: src/tokenizer/line_tokenizer.rs
assertion_line: 78
expression: "line_tokenizer(\"Mixed\\r\\nand\\rbare\")"
---
[

View file

@ -1,6 +1,5 @@
---
source: src/tokenizer/markdown_tokenizer.rs
assertion_line: 199
expression: "markdown_tokenizer(\"## Sub heading\")"
---
[

View file

@ -0,0 +1,24 @@
---
source: src/tokenizer/markdown_tokenizer.rs
expression: "markdown_tokenizer(\"###### Deep heading\")"
---
[
Token {
normalized: "###### Deep",
original: "###### Deep",
is_left_joinable: false,
is_right_joinable: true,
},
Token {
normalized: " heading",
original: " ",
is_left_joinable: true,
is_right_joinable: true,
},
Token {
normalized: "heading",
original: "heading",
is_left_joinable: true,
is_right_joinable: true,
},
]

View file

@ -30,7 +30,9 @@ where
/// Trivial implementation of Token when the normalized form is the same as the
/// original string
impl From<&str> for Token<String> {
fn from(text: &str) -> Self { Token::new(text.to_owned(), text.to_owned(), true, true) }
fn from(text: &str) -> Self {
Token::new(text.to_owned(), text.to_owned(), true, true)
}
}
impl<T> Token<T>
@ -51,18 +53,28 @@ where
}
}
pub fn original(&self) -> &str { &self.original }
pub fn original(&self) -> &str {
&self.original
}
pub fn set_normalized(&mut self, normalized: T) { self.normalized = normalized; }
pub fn set_normalized(&mut self, normalized: T) {
self.normalized = normalized;
}
pub fn normalized(&self) -> &T { &self.normalized }
pub fn normalized(&self) -> &T {
&self.normalized
}
pub fn get_original_length(&self) -> usize { self.original.chars().count() }
pub fn get_original_length(&self) -> usize {
self.original.chars().count()
}
}
impl<T> PartialEq for Token<T>
where
T: PartialEq + Clone + Debug,
{
fn eq(&self, other: &Self) -> bool { self.normalized == other.normalized }
fn eq(&self, other: &Self) -> bool {
self.normalized == other.normalized
}
}

View file

@ -18,7 +18,9 @@ pub struct CursorPosition {
impl CursorPosition {
#[cfg_attr(feature = "wasm", wasm_bindgen(constructor))]
#[must_use]
pub fn new(id: usize, char_index: usize) -> Self { Self { id, char_index } }
pub fn new(id: usize, char_index: usize) -> Self {
Self { id, char_index }
}
#[must_use]
pub fn with_index(&self, index: usize) -> Self {
@ -29,9 +31,13 @@ impl CursorPosition {
}
#[must_use]
pub fn id(&self) -> usize { self.id }
pub fn id(&self) -> usize {
self.id
}
#[cfg_attr(feature = "wasm", wasm_bindgen(js_name = characterIndex))]
#[must_use]
pub fn char_index(&self) -> usize { self.char_index }
pub fn char_index(&self) -> usize {
self.char_index
}
}

View file

@ -62,19 +62,27 @@ impl From<NumberOrText> for JsValue {
}
impl From<i64> for NumberOrText {
fn from(value: i64) -> Self { NumberOrText::Number(value) }
fn from(value: i64) -> Self {
NumberOrText::Number(value)
}
}
impl From<String> for NumberOrText {
fn from(value: String) -> Self { NumberOrText::Text(value) }
fn from(value: String) -> Self {
NumberOrText::Text(value)
}
}
impl From<&str> for NumberOrText {
fn from(value: &str) -> Self { NumberOrText::Text(value.to_owned()) }
fn from(value: &str) -> Self {
NumberOrText::Text(value.to_owned())
}
}
impl<'a> From<Cow<'a, str>> for NumberOrText {
fn from(value: Cow<'a, str>) -> Self { NumberOrText::Text(value.into_owned()) }
fn from(value: Cow<'a, str>) -> Self {
NumberOrText::Text(value.into_owned())
}
}
/// Error type for deserialisation failures
@ -105,5 +113,7 @@ impl std::error::Error for DeserialisationError {}
#[cfg(feature = "wasm")]
impl From<DeserialisationError> for JsValue {
fn from(error: DeserialisationError) -> Self { JsValue::from_str(&error.message) }
fn from(error: DeserialisationError) -> Self {
JsValue::from_str(&error.message)
}
}

View file

@ -18,11 +18,17 @@ pub struct SpanWithHistory {
#[cfg_attr(feature = "wasm", wasm_bindgen)]
impl SpanWithHistory {
#[must_use]
pub fn new(text: String, history: History) -> Self { SpanWithHistory { text, history } }
pub fn new(text: String, history: History) -> Self {
SpanWithHistory { text, history }
}
#[must_use]
pub fn history(&self) -> History { self.history }
pub fn history(&self) -> History {
self.history
}
#[must_use]
pub fn text(&self) -> String { self.text.clone() }
pub fn text(&self) -> String {
self.text.clone()
}
}

View file

@ -33,15 +33,21 @@ impl TextWithCursors {
}
#[must_use]
pub fn text(&self) -> String { self.text.to_string() }
pub fn text(&self) -> String {
self.text.clone()
}
#[must_use]
pub fn cursors(&self) -> Vec<CursorPosition> { self.cursors.clone() }
pub fn cursors(&self) -> Vec<CursorPosition> {
self.cursors.clone()
}
}
impl TextWithCursors {
#[must_use]
pub fn text_ref(&self) -> &str { &self.text }
pub fn text_ref(&self) -> &str {
&self.text
}
}
impl<'a> From<&'a str> for TextWithCursors {

View file

@ -94,7 +94,9 @@ impl V {
}
}
fn len(&self) -> usize { self.v.len() }
fn len(&self) -> usize {
self.v.len()
}
}
impl Index<isize> for V {

View file

@ -35,7 +35,9 @@ impl StringBuilder<'_> {
}
/// Insert a string at the end of the built buffer
pub fn insert(&mut self, text: &str) { self.buffer.push_str(text); }
pub fn insert(&mut self, text: &str) {
self.buffer.push_str(text);
}
/// Skip copying `length` characters from the original string to the built
/// buffer
@ -64,7 +66,9 @@ impl StringBuilder<'_> {
/// Returns the currently built buffer and clears it to allow consuming
/// the result incrementally.
pub fn take(&mut self) -> String { std::mem::take(&mut self.buffer) }
pub fn take(&mut self) -> String {
std::mem::take(&mut self.buffer)
}
/// Get a slice of the remaining original string. The slice starts from
/// where the next delete/retain operation would start and is of length

View file

@ -139,13 +139,19 @@ pub struct TextWithCursorsAndHistory {
#[wasm_bindgen]
impl TextWithCursorsAndHistory {
#[must_use]
pub fn text(&self) -> String { self.text_with_cursors.text() }
pub fn text(&self) -> String {
self.text_with_cursors.text()
}
#[must_use]
pub fn cursors(&self) -> Vec<CursorPosition> { self.text_with_cursors.cursors() }
pub fn cursors(&self) -> Vec<CursorPosition> {
self.text_with_cursors.cursors()
}
#[must_use]
pub fn history(&self) -> Vec<SpanWithHistory> { self.history.clone() }
pub fn history(&self) -> Vec<SpanWithHistory> {
self.history.clone()
}
}
/// Returns the UTF8 parsed string if it's a text, or `None` if it's likely