Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

fix(core): seal extension traits

Elijah Pottere40967cf3e8e
diff --git a/harper-core/src/char_ext.rs b/harper-core/src/char_ext.rs
index 1e67e143b..ef218a988 100644
--- a/harper-core/src/char_ext.rs
+++ b/harper-core/src/char_ext.rs
@@ -3,7 +3,13 @@ use unicode_width::UnicodeWidthChar;
use crate::Punctuation;
-pub trait CharExt {
+mod private {
+ pub trait Sealed {}
+
+ impl Sealed for char {}
+}
+
+pub trait CharExt: private::Sealed {
fn is_cjk(&self) -> bool;
/// Whether a character can be a component of an English word.
fn is_english_lingual(&self) -> bool;
diff --git a/harper-core/src/token_string_ext.rs b/harper-core/src/token_string_ext.rs
index 69ede6d1f..8b3848192 100644
--- a/harper-core/src/token_string_ext.rs
+++ b/harper-core/src/token_string_ext.rs
@@ -47,8 +47,18 @@ macro_rules! create_fns_for {
};
}
+mod private {
+ use crate::{Document, Token};
+
+ pub trait Sealed {}
+
+ impl Sealed for [Token] {}
+
+ impl Sealed for Document {}
+}
+
/// Extension methods for [`Token`] sequences that make them easier to wrangle and query.
-pub trait TokenStringExt {
+pub trait TokenStringExt: private::Sealed {
fn first_sentence_word(&self) -> Option<&Token>;
fn first_non_whitespace(&self) -> Option<&Token>;
/// Grab the span that represents the beginning of the first element and the
diff --git a/harper-core/src/vec_ext.rs b/harper-core/src/vec_ext.rs
index 2c1bcf9d1..80d3c7d9c 100644
--- a/harper-core/src/vec_ext.rs
+++ b/harper-core/src/vec_ext.rs
@@ -1,7 +1,13 @@
use std::collections::VecDeque;
+mod private {
+ pub trait Sealed {}
+
+ impl<T> Sealed for Vec<T> {}
+}
+
/// Extensions on top of [`Vec`] that make certain common operations easier.
-pub trait VecExt {
+pub trait VecExt: private::Sealed {
/// Removes a list of indices from a Vector.
/// Assumes that the provided indices are already in sorted order.
fn remove_indices(&mut self, to_remove: VecDeque<usize>);