Skip to content

Commit

Permalink
remove use of impl Trait from function return type
Browse files Browse the repository at this point in the history
  • Loading branch information
rluvaton committed Dec 31, 2024
1 parent 333ecb9 commit 1a695fb
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions arrow-string/src/predicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,29 @@ use memchr::memmem::Finder;
use regex::{
bytes::Regex as BinaryRegex, bytes::RegexBuilder as BinaryRegexBuilder, Regex, RegexBuilder,
};
use std::iter::zip;
use std::{iter::zip, str::Chars};

pub trait SupportedPredicateItem: PartialEq
where
Self: 'static,
{
type CharIter<'a>: Iterator<Item = char>;

const PERCENT: &'static Self;
const PERCENT_ESCAPED: &'static Self;

fn len(&self) -> usize;

fn as_bytes(&self) -> &[u8];

fn to_char_iter(&self) -> impl Iterator<Item = char>;
// After the minimum supported Rust version is >= 1.75.0 we can change the return type to be
// `impl Iterator<Item = char>`
fn to_char_iter(&self) -> Self::CharIter<'_>;
}

impl SupportedPredicateItem for str {
type CharIter<'a> = Chars<'a>;

const PERCENT: &'static str = "%";
const PERCENT_ESCAPED: &'static str = "\\%";

Expand All @@ -54,12 +60,14 @@ impl SupportedPredicateItem for str {
}

#[inline]
fn to_char_iter(&self) -> impl Iterator<Item = char> {
fn to_char_iter(&self) -> Self::CharIter<'_> {
self.chars()
}
}

impl SupportedPredicateItem for [u8] {
type CharIter<'a> = std::iter::Map<std::slice::Iter<'a, u8>, for<'b> fn(&'b u8) -> char>;

const PERCENT: &'static [u8] = b"%";
const PERCENT_ESCAPED: &'static [u8] = b"\\%";

Expand All @@ -74,7 +82,7 @@ impl SupportedPredicateItem for [u8] {
}

#[inline]
fn to_char_iter(&self) -> impl Iterator<Item = char> {
fn to_char_iter(&self) -> Self::CharIter<'_> {
self.iter().map(|&b| b as char)
}
}
Expand Down

0 comments on commit 1a695fb

Please sign in to comment.