Skip to content

Commit

Permalink
[utf-16] Move iterator bounds to the TextSource trait
Browse files Browse the repository at this point in the history
  • Loading branch information
jfkthame committed Oct 30, 2023
1 parent 52cc9ee commit 512846a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
4 changes: 1 addition & 3 deletions src/explicit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ pub fn compute<'a, T: TextSource<'a> + ?Sized>(
original_classes: &[BidiClass],
levels: &mut [Level],
processing_classes: &mut [BidiClass],
) where
<T as TextSource<'a>>::IndexLenIter: Iterator<Item = (usize, usize)>,
{
) {
assert_eq!(text.len(), original_classes.len());

// <http://www.unicode.org/reports/tr9/#X1>
Expand Down
10 changes: 2 additions & 8 deletions src/implicit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,7 @@ pub fn resolve_neutral<'a, D: BidiDataSource, T: TextSource<'a> + ?Sized>(
levels: &[Level],
original_classes: &[BidiClass],
processing_classes: &mut [BidiClass],
) where
<T as TextSource<'a>>::CharIndexIter: Iterator<Item = (usize, char)>,
<T as TextSource<'a>>::CharIter: Iterator<Item = char>,
{
) {
// e = embedding direction
let e: BidiClass = levels[sequence.runs[0].start].bidi_class();
let not_e = if e == BidiClass::L {
Expand Down Expand Up @@ -487,10 +484,7 @@ fn identify_bracket_pairs<'a, T: TextSource<'a> + ?Sized, D: BidiDataSource>(
data_source: &D,
run_sequence: &IsolatingRunSequence,
original_classes: &[BidiClass],
) -> Vec<BracketPair>
where
<T as TextSource<'a>>::CharIndexIter: Iterator<Item = (usize, char)>,
{
) -> Vec<BracketPair> {
let mut ret = vec![];
let mut stack = vec![];

Expand Down
22 changes: 9 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ use crate::BidiClass::*;
/// We implement this for str (UTF-8) and for [u16] (UTF-16, native-endian).
/// (For internal unicode-bidi use; API may be unstable.)
/// This trait is sealed and cannot be implemented for types outside this crate.
pub trait TextSource<'text>: private::Sealed {
pub trait TextSource<'text>: private::Sealed
where
<Self as TextSource<'text>>::CharIndexIter: Iterator<Item = (usize, char)>,
<Self as TextSource<'text>>::CharIter: Iterator<Item = char>,
<Self as TextSource<'text>>::IndexLenIter: Iterator<Item = (usize, usize)>,
{
type CharIter;
type CharIndexIter;
type IndexLenIter;
Expand Down Expand Up @@ -283,10 +288,7 @@ fn compute_initial_info<'a, D: BidiDataSource, T: TextSource<'a> + ?Sized>(
data_source: &D,
text: &'a T,
default_para_level: Option<Level>,
) -> (Vec<BidiClass>, Vec<ParagraphInfo>, Vec<bool>)
where
<T as TextSource<'a>>::CharIndexIter: Iterator<Item = (usize, char)>,
{
) -> (Vec<BidiClass>, Vec<ParagraphInfo>, Vec<bool>) {
let mut original_classes = Vec::with_capacity(text.len());

// The stack contains the starting code unit index for each nested isolate we're inside.
Expand Down Expand Up @@ -835,11 +837,7 @@ fn compute_bidi_info_for_para<'a, D: BidiDataSource, T: TextSource<'a> + ?Sized>
original_classes: &[BidiClass],
processing_classes: &mut [BidiClass],
levels: &mut Vec<Level>,
) where
<T as TextSource<'a>>::CharIndexIter: Iterator<Item = (usize, char)>,
<T as TextSource<'a>>::CharIter: Iterator<Item = char>,
<T as TextSource<'a>>::IndexLenIter: Iterator<Item = (usize, usize)>,
{
) {
let new_len = levels.len() + para.range.len();
levels.resize(new_len, para.level);
if para.level == LTR_LEVEL && is_pure_ltr {
Expand Down Expand Up @@ -886,9 +884,7 @@ fn reorder_levels<'a, T: TextSource<'a> + ?Sized>(
line_levels: &mut [Level],
line_text: &'a T,
para_level: Level,
) where
<T as TextSource<'a>>::CharIndexIter: Iterator<Item = (usize, char)>,
{
) {
// Reset some whitespace chars to paragraph level.
// <http://www.unicode.org/reports/tr9/#L1>
let mut reset_from: Option<usize> = Some(0);
Expand Down

0 comments on commit 512846a

Please sign in to comment.