Move bytes implementation into a submodule in abstractions

This commit is contained in:
Armin Ronacher 2021-02-03 14:29:24 +01:00
parent 8a6d1716ec
commit 3164c72062

View file

@ -1,6 +1,3 @@
#[cfg(feature = "bytes")]
use bstr::ByteSlice;
use std::borrow::Cow;
use std::hash::Hash;
use std::ops::Range;
@ -47,15 +44,6 @@ impl<'a, T: DiffableStr + ?Sized> DiffableStrRef for Cow<'a, T> {
}
}
#[cfg(feature = "bytes")]
impl DiffableStrRef for Vec<u8> {
type Output = [u8];
fn as_diffable_str(&self) -> &[u8] {
self.as_slice()
}
}
/// All supported diffable strings.
///
/// The text module can work with different types of strings depending
@ -221,10 +209,23 @@ impl DiffableStr for str {
}
}
#[cfg(feature = "bytes")]
mod bytes_support {
use super::*;
use bstr::ByteSlice;
impl DiffableStrRef for Vec<u8> {
type Output = [u8];
fn as_diffable_str(&self) -> &[u8] {
self.as_slice()
}
}
/// Allows viewing ASCII compatible byte slices as strings.
///
/// Requires the `bytes` feature.
#[cfg(feature = "bytes")]
impl DiffableStr for [u8] {
fn tokenize_lines(&self) -> Vec<&Self> {
let mut iter = self.char_indices().peekable();
@ -332,6 +333,7 @@ impl DiffableStr for [u8] {
self
}
}
}
#[test]
fn test_split_lines() {