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::borrow::Cow;
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
use std::ops::Range;
|
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.
|
/// All supported diffable strings.
|
||||||
///
|
///
|
||||||
/// The text module can work with different types of strings depending
|
/// 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.
|
/// Allows viewing ASCII compatible byte slices as strings.
|
||||||
///
|
///
|
||||||
/// Requires the `bytes` feature.
|
/// Requires the `bytes` feature.
|
||||||
#[cfg(feature = "bytes")]
|
|
||||||
impl DiffableStr for [u8] {
|
impl DiffableStr for [u8] {
|
||||||
fn tokenize_lines(&self) -> Vec<&Self> {
|
fn tokenize_lines(&self) -> Vec<&Self> {
|
||||||
let mut iter = self.char_indices().peekable();
|
let mut iter = self.char_indices().peekable();
|
||||||
|
|
@ -332,6 +333,7 @@ impl DiffableStr for [u8] {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_split_lines() {
|
fn test_split_lines() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue