Move bytes implementation into a submodule in abstractions
This commit is contained in:
parent
8a6d1716ec
commit
3164c72062
1 changed files with 97 additions and 95 deletions
|
|
@ -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,11 +209,24 @@ impl DiffableStr for str {
|
|||
}
|
||||
}
|
||||
|
||||
/// Allows viewing ASCII compatible byte slices as strings.
|
||||
///
|
||||
/// Requires the `bytes` feature.
|
||||
#[cfg(feature = "bytes")]
|
||||
impl DiffableStr for [u8] {
|
||||
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.
|
||||
impl DiffableStr for [u8] {
|
||||
fn tokenize_lines(&self) -> Vec<&Self> {
|
||||
let mut iter = self.char_indices().peekable();
|
||||
let mut last_pos = 0;
|
||||
|
|
@ -331,6 +332,7 @@ impl DiffableStr for [u8] {
|
|||
fn as_bytes(&self) -> &[u8] {
|
||||
self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue