Documentation updates

This commit is contained in:
Armin Ronacher 2021-02-03 01:12:34 +01:00
parent 844769ae19
commit daa3d6cf5e
3 changed files with 54 additions and 31 deletions

View file

@ -13,6 +13,8 @@ use std::ops::Range;
///
/// This trait is used in the library whenever it's nice to be able to pass
/// strings of different types in.
///
/// Requires the `text` feature.
pub trait DiffableStrRef {
/// The type of the resolved [`DiffableStr`].
type Output: DiffableStr + ?Sized;
@ -60,6 +62,8 @@ impl DiffableStrRef for Vec<u8> {
/// on how the crate is compiled. Out of the box `&str` is always supported
/// but with the `bytes` feature one can also work with `[u8]` slices for
/// as long as they are ASCII compatible.
///
/// Requires the `text` feature.
pub trait DiffableStr: Hash + PartialEq + PartialOrd + Ord + Eq + ToOwned {
/// Splits the value into newlines with newlines attached.
fn tokenize_lines(&self) -> Vec<&Self>;
@ -217,6 +221,9 @@ impl DiffableStr for str {
}
}
/// 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> {

View file

@ -17,6 +17,8 @@ use crate::udiff::UnifiedDiff;
use crate::{capture_diff_slices, get_diff_ratio, group_diff_ops, Algorithm, Change, DiffOp};
/// A builder type config for more complex uses of [`TextDiff`].
///
/// Requires the `text` feature.
#[derive(Clone, Debug)]
pub struct TextDiffConfig {
algorithm: Algorithm,
@ -159,7 +161,9 @@ impl TextDiffConfig {
}
}
/// Captures diff op codes for textual diffs
/// Captures diff op codes for textual diffs.
///
/// Requires the `text` feature.
pub struct TextDiff<'old, 'new, 'bufs, T: DiffableStr + ?Sized> {
old: Cow<'bufs, [&'old T]>,
new: Cow<'bufs, [&'new T]>,
@ -333,6 +337,8 @@ impl<'old, 'new, 'bufs, T: DiffableStr + ?Sized + 'old + 'new> TextDiff<'old, 'n
/// );
/// assert_eq!(matches, vec!["apple", "ape"]);
/// ```
///
/// Requires the `text` feature.
pub fn get_close_matches<'a, T: DiffableStr + ?Sized>(
word: &T,
possibilities: &[&'a T],