From f04972f1e12d764c3ba7e973a956e9aa7d56a1e2 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Sat, 6 Dec 2025 11:55:01 +0000 Subject: [PATCH] Rename NumberOrString --- src/lib.rs | 4 +-- src/operation_transformation/edited_text.rs | 22 ++++++------ src/types.rs | 2 +- ...{number_or_string.rs => number_or_text.rs} | 34 +++++++++---------- 4 files changed, 31 insertions(+), 31 deletions(-) rename src/types/{number_or_string.rs => number_or_text.rs} (69%) diff --git a/src/lib.rs b/src/lib.rs index 0720cf2..654daa7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -218,8 +218,8 @@ mod utils; pub use operation_transformation::{DiffError, EditedText, reconcile}; pub use tokenizer::{BuiltinTokenizer, Tokenizer, token::Token}; pub use types::{ - cursor_position::CursorPosition, history::History, number_or_string::NumberOrString, - side::Side, span_with_history::SpanWithHistory, text_with_cursors::TextWithCursors, + cursor_position::CursorPosition, history::History, number_or_text::NumberOrText, side::Side, + span_with_history::SpanWithHistory, text_with_cursors::TextWithCursors, }; #[cfg(feature = "wasm")] diff --git a/src/operation_transformation/edited_text.rs b/src/operation_transformation/edited_text.rs index b47936e..1f41cb1 100644 --- a/src/operation_transformation/edited_text.rs +++ b/src/operation_transformation/edited_text.rs @@ -12,7 +12,7 @@ use crate::{ raw_operation::RawOperation, tokenizer::Tokenizer, types::{ - history::History, number_or_string::NumberOrString, side::Side, + history::History, number_or_text::NumberOrText, side::Side, span_with_history::SpanWithHistory, }, utils::string_builder::StringBuilder, @@ -366,8 +366,8 @@ where /// /// Panics if there's an integer overflow in i64. #[must_use] - pub fn to_diff(&self) -> Vec { - let mut result: Vec = Vec::with_capacity(self.operations.len()); + pub fn to_diff(&self) -> Vec { + let mut result: Vec = Vec::with_capacity(self.operations.len()); let mut previous_equal: Option = None; for operation in &self.operations { @@ -382,7 +382,7 @@ where Operation::Insert { text, .. } => { if let Some(prev_length) = previous_equal { - result.push(NumberOrString::Number( + result.push(NumberOrText::Number( i64::try_from(prev_length).expect("prev_length must fit in i64"), )); previous_equal = None; @@ -392,7 +392,7 @@ where .iter() .map(super::super::tokenizer::token::Token::original) .collect(); - result.push(NumberOrString::Text(text)); + result.push(NumberOrText::Text(text)); } Operation::Delete { @@ -400,7 +400,7 @@ where .. } => { if let Some(prev_length) = previous_equal { - result.push(NumberOrString::Number( + result.push(NumberOrText::Number( i64::try_from(prev_length).expect("prev_length must fit in i64"), )); previous_equal = None; @@ -408,13 +408,13 @@ where let count = i64::try_from(*deleted_character_count) .expect("deleted_character_count must fit in i64"); - result.push(NumberOrString::Number(-count)); + result.push(NumberOrText::Number(-count)); } } } if let Some(prev_length) = previous_equal { - result.push(NumberOrString::Number( + result.push(NumberOrText::Number( i64::try_from(prev_length).expect("prev_length must fit in i64"), )); } @@ -434,7 +434,7 @@ where /// Panics if there's an integer overflow in i64. pub fn from_diff( original_text: &'a str, - diff: Vec, + diff: Vec, tokenizer: &Tokenizer, ) -> Result, DiffError> { let mut operations: Vec> = Vec::with_capacity(diff.len()); @@ -442,7 +442,7 @@ where for item in diff { match item { - NumberOrString::Number(length) => { + NumberOrText::Number(length) => { if length >= 0 { let length = usize::try_from(length).expect("length must fit in usize"); @@ -483,7 +483,7 @@ where order += length; } } - NumberOrString::Text(text) => { + NumberOrText::Text(text) => { let tokens = tokenizer(&text); operations.push(Operation::create_insert(order, tokens)); } diff --git a/src/types.rs b/src/types.rs index b5c2f7c..03bb7b6 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,6 +1,6 @@ pub mod cursor_position; pub mod history; -pub mod number_or_string; +pub mod number_or_text; pub mod side; pub mod span_with_history; pub mod text_with_cursors; diff --git a/src/types/number_or_string.rs b/src/types/number_or_text.rs similarity index 69% rename from src/types/number_or_string.rs rename to src/types/number_or_text.rs index 0aade44..bb42bc7 100644 --- a/src/types/number_or_string.rs +++ b/src/types/number_or_text.rs @@ -12,18 +12,18 @@ const INTEGRAL_LIMIT: f64 = (1u64 << 53) as f64; #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", serde(untagged))] #[derive(Debug, Clone, PartialEq)] -pub enum NumberOrString { +pub enum NumberOrText { Number(i64), Text(String), } #[cfg(feature = "wasm")] -impl TryFrom for NumberOrString { +impl TryFrom for NumberOrText { type Error = DeserialisationError; fn try_from(value: JsValue) -> Result { if let Ok(num) = value.clone().try_into() { - return Ok(NumberOrString::Number(num)); + return Ok(NumberOrText::Number(num)); } if let Some(num) = value.clone().as_f64() { @@ -34,11 +34,11 @@ impl TryFrom for NumberOrString { } #[allow(clippy::cast_possible_truncation)] - return Ok(NumberOrString::Number(num.round() as i64)); + return Ok(NumberOrText::Number(num.round() as i64)); } if let Ok(text) = value.try_into() { - return Ok(NumberOrString::Text(text)); + return Ok(NumberOrText::Text(text)); } Err(DeserialisationError::new( @@ -48,29 +48,29 @@ impl TryFrom for NumberOrString { } #[cfg(feature = "wasm")] -impl From for JsValue { - fn from(value: NumberOrString) -> Self { +impl From for JsValue { + fn from(value: NumberOrText) -> Self { match value { - NumberOrString::Number(num) => JsValue::from(num), - NumberOrString::Text(text) => JsValue::from(text), + NumberOrText::Number(num) => JsValue::from(num), + NumberOrText::Text(text) => JsValue::from(text), } } } -impl From for NumberOrString { - fn from(value: i64) -> Self { NumberOrString::Number(value) } +impl From for NumberOrText { + fn from(value: i64) -> Self { NumberOrText::Number(value) } } -impl From for NumberOrString { - fn from(value: String) -> Self { NumberOrString::Text(value) } +impl From for NumberOrText { + fn from(value: String) -> Self { NumberOrText::Text(value) } } -impl From<&str> for NumberOrString { - fn from(value: &str) -> Self { NumberOrString::Text(value.to_owned()) } +impl From<&str> for NumberOrText { + fn from(value: &str) -> Self { NumberOrText::Text(value.to_owned()) } } -impl<'a> From> for NumberOrString { - fn from(value: Cow<'a, str>) -> Self { NumberOrString::Text(value.into_owned()) } +impl<'a> From> for NumberOrText { + fn from(value: Cow<'a, str>) -> Self { NumberOrText::Text(value.into_owned()) } } /// Error type for deserialisation failures