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

@ -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 {