diff --git a/Cargo.toml b/Cargo.toml index d89c2b5..aed8cf4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,8 @@ readme = "README.md" all-features = true [features] -default = [] +default = ["text"] +text = [] unicode = ["unicode-segmentation"] [dev-dependencies] diff --git a/Makefile b/Makefile index 7bc49a5..1d2a11d 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,9 @@ doc: @cargo doc --all-features test: + @cargo test @cargo test --all-features + @cargo test --no-default-features format: @rustup component add rustfmt 2> /dev/null diff --git a/src/lib.rs b/src/lib.rs index 7af53db..1c1b0c7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,12 +1,13 @@ //! This crate implements diffing utilities. It attempts to provide an abstraction //! interface over different types of diffing algorithms. It's based on the //! the diff algorithm implementations of [pijul](https://pijul.org/). - //! ```rust +//! # #[cfg(feature = "text")] { //! use similar::text::TextDiff; //! # let old_text = ""; //! # let new_text = ""; //! let diff = TextDiff::from_chars("Hello World", "Hallo Welt"); +//! # } //! ``` //! //! ## Functionality @@ -17,13 +18,15 @@ //! * [`text`]: This extends the general diffing functionality to text (and more //! specifically line) based diff operations. //! -//! ## Optional Features +//! ## Features //! //! The crate by default does not have any dependencies however for some use -//! cases it's useful to pull in extra functionality: +//! cases it's useful to pull in extra functionality. Likewise you can turn +//! off some functionality. //! //! * `unicode`: when this feature is enabled the text diffing functionality //! gains the ability to diff on a grapheme instead of character level. This //! is particularly useful when working with text containing emojis. +//! * `text`: this feature is enabled by default and enables the [`text`] module. pub mod algorithms; pub mod text; diff --git a/src/text.rs b/src/text.rs index 7734bda..c0cdab1 100644 --- a/src/text.rs +++ b/src/text.rs @@ -47,6 +47,7 @@ //! //! Because the [`TextDiff::grouped_ops`] method can isolate clusters of changes //! this even works for very long files if paired with this method. +#![cfg(feature = "text")] use std::borrow::Cow; use std::fmt; use std::io;