From 0f9ada1c4e2e534340c47ab4d38abb5ebdf6cd7b Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Sat, 5 May 2018 23:02:51 +0200 Subject: [PATCH] fix: Return a byte slice instead of a possibly wrong utf-8 str --- src/lib.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 870964cd9..b50846144 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,7 +30,7 @@ impl<'m, 'v, T: 'v, A> StreamBuilder<'m, 'v, T, A> { } impl<'m, 'v, 'a, T: 'v + 'a, A: Automaton> fst::IntoStreamer<'a> for StreamBuilder<'m, 'v, T, A> { - type Item = (&'a str, &'a [T]); + type Item = >::Item; type Into = Stream<'m, 'v, T, A>; fn into_stream(self) -> Self::Into { @@ -47,13 +47,12 @@ pub struct Stream<'m, 'v, T: 'v, A: Automaton = fst::automaton::AlwaysMatch> { } impl<'m, 'v, 'a, T: 'v + 'a, A: Automaton> fst::Streamer<'a> for Stream<'m, 'v, T, A> { - type Item = (&'a str, &'a [T]); + type Item = (&'a [u8], &'a [T]); fn next(&'a mut self) -> Option { // Here we can't just `map` because of some borrow rules match self.inner.next() { Some((key, i)) => { - let key = unsafe { from_utf8_unchecked(key) }; let values = unsafe { self.values.get_unchecked(i as usize) }; Some((key, values)) }, @@ -72,7 +71,7 @@ where A: Automaton, A::State: Clone, { - type Item = (&'a str, &'a [T], A::State); + type Item = >::Item; type Into = StreamWithState<'m, 'v, T, A>; fn into_stream(self) -> Self::Into { @@ -93,12 +92,11 @@ where A: Automaton, A::State: Clone, { - type Item = (&'a str, &'a [T], A::State); + type Item = (&'a [u8], &'a [T], A::State); fn next(&'a mut self) -> Option { match self.inner.next() { - Some((k, i, state)) => { - let key = unsafe { from_utf8_unchecked(k) }; + Some((key, i, state)) => { let values = unsafe { self.values.get_unchecked(i as usize) }; Some((key, values, state)) },