diff options
author | Joshua Dutton <jb.dutton@gmail.com> | 2019-08-18 18:26:35 -0400 |
---|---|---|
committer | Paul Masurel <paul.masurel@gmail.com> | 2019-08-19 07:26:35 +0900 |
commit | 9f74786db2028d8c36b6f8c4d02c1f0945d48022 (patch) | |
tree | 3472401f47ca16c5a82d78886cd4bd349329f7f5 | |
parent | 32e5d7a0c7caf8c4d2420773daaad3c7c1361b3c (diff) |
Update import statements in examples, doctests (#633)
Update import statements to edition 2018, including removing
`extern crate` and `#[macro_use]`. Alphabetize the statements.
28 files changed, 44 insertions, 123 deletions
diff --git a/examples/basic_search.rs b/examples/basic_search.rs index 4f9d39d..c8ac36c 100644 --- a/examples/basic_search.rs +++ b/examples/basic_search.rs @@ -12,13 +12,10 @@ // --- // Importing tantivy... -#[macro_use] -extern crate tantivy; use tantivy::collector::TopDocs; use tantivy::query::QueryParser; use tantivy::schema::*; -use tantivy::Index; -use tantivy::ReloadPolicy; +use tantivy::{doc, Index, ReloadPolicy}; use tempfile::TempDir; fn main() -> tantivy::Result<()> { diff --git a/examples/custom_collector.rs b/examples/custom_collector.rs index e63eb9f..c277ede 100644 --- a/examples/custom_collector.rs +++ b/examples/custom_collector.rs @@ -9,15 +9,12 @@ // --- // Importing tantivy... -#[macro_use] -extern crate tantivy; use tantivy::collector::{Collector, SegmentCollector}; use tantivy::fastfield::FastFieldReader; use tantivy::query::QueryParser; use tantivy::schema::Field; use tantivy::schema::{Schema, FAST, INDEXED, TEXT}; -use tantivy::SegmentReader; -use tantivy::{Index, TantivyError}; +use tantivy::{doc, Index, SegmentReader, TantivyError}; #[derive(Default)] struct Stats { diff --git a/examples/custom_tokenizer.rs b/examples/custom_tokenizer.rs index 5730adb..4db6d10 100644 --- a/examples/custom_tokenizer.rs +++ b/examples/custom_tokenizer.rs @@ -2,14 +2,11 @@ // // In this example, we'll see how to define a tokenizer pipeline // by aligning a bunch of `TokenFilter`. - -#[macro_use] -extern crate tantivy; use tantivy::collector::TopDocs; use tantivy::query::QueryParser; use tantivy::schema::*; use tantivy::tokenizer::NgramTokenizer; -use tantivy::Index; +use tantivy::{doc, Index}; fn main() -> tantivy::Result<()> { // # Defining the schema diff --git a/examples/deleting_updating_documents.rs b/examples/deleting_updating_documents.rs index 82fdd90..1eda6ce 100644 --- a/examples/deleting_updating_documents.rs +++ b/examples/deleting_updating_documents.rs @@ -8,13 +8,10 @@ // // --- // Importing tantivy... -#[macro_use] -extern crate tantivy; use tantivy::collector::TopDocs; use tantivy::query::TermQuery; use tantivy::schema::*; -use tantivy::Index; -use tantivy::IndexReader; +use tantivy::{doc, Index, IndexReader}; // A simple helper function to fetch a single document // given its id from our index. diff --git a/examples/faceted_search.rs b/examples/faceted_search.rs index 302d613..7ac67c3 100644 --- a/examples/faceted_search.rs +++ b/examples/faceted_search.rs @@ -12,12 +12,10 @@ // --- // Importing tantivy... -#[macro_use] -extern crate tantivy; use tantivy::collector::FacetCollector; use tantivy::query::AllQuery; use tantivy::schema::*; -use tantivy::Index; +use tantivy::{doc, Index}; use tempfile::TempDir; fn main() -> tantivy::Result<()> { diff --git a/examples/integer_range_search.rs b/examples/integer_range_search.rs index dea3145..12edd6e 100644 --- a/examples/integer_range_search.rs +++ b/examples/integer_range_search.rs @@ -2,14 +2,10 @@ // // Below is an example of creating an indexed integer field in your schema // You can use RangeQuery to get a Count of all occurrences in a given range. - -#[macro_use] -extern crate tantivy; use tantivy::collector::Count; use tantivy::query::RangeQuery; use tantivy::schema::{Schema, INDEXED}; -use tantivy::Index; -use tantivy::Result; +use tantivy::{doc, Index, Result}; fn run() -> Result<()> { // For the sake of simplicity, this schema will only have 1 field diff --git a/examples/iterating_docs_and_positions.rs b/examples/iterating_docs_and_positions.rs index 4668de3..0be84ec 100644 --- a/examples/iterating_docs_and_positions.rs +++ b/examples/iterating_docs_and_positions.rs @@ -9,11 +9,8 @@ // --- // Importing tantivy... -#[macro_use] -extern crate tantivy; use tantivy::schema::*; -use tantivy::Index; -use tantivy::{DocId, DocSet, Postings}; +use tantivy::{doc, DocId, DocSet, Index, Postings}; fn main() -> tantivy::Result<()> { // We first create a schema for the sake of the diff --git a/examples/multiple_producer.rs b/examples/multiple_producer.rs index 912c431..6841cf8 100644 --- a/examples/multiple_producer.rs +++ b/examples/multiple_producer.rs @@ -25,14 +25,11 @@ // --- // Importing tantivy... -#[macro_use] -extern crate tantivy; use std::sync::{Arc, RwLock}; use std::thread; use std::time::Duration; use tantivy::schema::{Schema, STORED, TEXT}; -use tantivy::Opstamp; -use tantivy::{Index, IndexWriter}; +use tantivy::{doc, Index, IndexWriter, Opstamp}; fn main() -> tantivy::Result<()> { // # Defining the schema diff --git a/examples/snippet.rs b/examples/snippet.rs index 054d760..eab6405 100644 --- a/examples/snippet.rs +++ b/examples/snippet.rs @@ -7,13 +7,10 @@ // --- // Importing tantivy... -#[macro_use] -extern crate tantivy; use tantivy::collector::TopDocs; use tantivy::query::QueryParser; use tantivy::schema::*; -use tantivy::Index; -use tantivy::{Snippet, SnippetGenerator}; +use tantivy::{doc, Index, Snippet, SnippetGenerator}; use tempfile::TempDir; fn main() -> tantivy::Result<()> { diff --git a/examples/stop_words.rs b/examples/stop_words.rs index 9246e23..0911129 100644 --- a/examples/stop_words.rs +++ b/examples/stop_words.rs @@ -11,13 +11,11 @@ // --- // Importing tantivy... -#[macro_use] -extern crate tantivy; use tantivy::collector::TopDocs; use tantivy::query::QueryParser; use tantivy::schema::*; use tantivy::tokenizer::*; -use tantivy::Index; +use tantivy::{doc, Index}; fn main() -> tantivy::Result<()> { // this example assumes you understand the content in `basic_search` diff --git a/src/collector/count_collector.rs b/src/collector/count_collector.rs index c5db472..a180491 100644 --- a/src/collector/count_collector.rs +++ b/src/collector/count_collector.rs @@ -10,12 +10,10 @@ use crate::SegmentReader; /// documents match the query. /// /// ```rust -/// #[macro_use] -/// extern crate tantivy; -/// use tantivy::schema::{Schema, TEXT}; -/// use tantivy::{Index, Result}; /// use tantivy::collector::Count; /// use tantivy::query::QueryParser; +/// use tantivy::schema::{Schema, TEXT}; +/// use tantivy::{doc, Index, Result}; /// /// # fn main() { example().unwrap(); } /// fn example() -> Result<()> { diff --git a/src/collector/facet_collector.rs b/src/collector/facet_collector.rs index 46fd240..5cd0563 100644 --- a/src/collector/facet_collector.rs +++ b/src/collector/facet_collector.rs @@ -81,12 +81,10 @@ fn facet_depth(facet_bytes: &[u8]) -> usize { /// /// /// ```rust -/// #[macro_use] -/// extern crate tantivy; -/// use tantivy::schema::{Facet, Schema, TEXT}; -/// use tantivy::{Index, Result}; /// use tantivy::collector::FacetCollector; /// use tantivy::query::AllQuery; +/// use tantivy::schema::{Facet, Schema, TEXT}; +/// use tantivy::{doc, Index, Result}; /// /// # fn main() { example().unwrap(); } /// fn example() -> Result<()> { diff --git a/src/collector/mod.rs b/src/collector/mod.rs index c19282e..f5bfded 100644 --- a/src/collector/mod.rs +++ b/src/collector/mod.rs @@ -35,7 +35,6 @@ The resulting `Fruit` will then be a typed tuple with each collector's original in their respective position. ```rust -# extern crate tantivy; # use tantivy::schema::*; # use tantivy::*; # use tantivy::query::*; diff --git a/src/collector/multi_collector.rs b/src/collector/multi_collector.rs index 5358a6c..a7b2386 100644 --- a/src/collector/multi_collector.rs +++ b/src/collector/multi_collector.rs @@ -105,12 +105,10 @@ impl<TFruit: Fruit> FruitHandle<TFruit> { /// [Combining several collectors section of the collector documentation](./index.html#combining-several-collectors). /// /// ```rust -/// #[macro_use] -/// extern crate tantivy; -/// use tantivy::schema::{Schema, TEXT}; -/// use tantivy::{Index, Result}; /// use tantivy::collector::{Count, TopDocs, MultiCollector}; /// use tantivy::query::QueryParser; +/// use tantivy::schema::{Schema, TEXT}; +/// use tantivy::{doc, Index, Result}; /// /// # fn main() { example().unwrap(); } /// fn example() -> Result<()> { diff --git a/src/collector/top_score_collector.rs b/src/collector/top_score_collector.rs index a4fbac2..7159ed4 100644 --- a/src/collector/top_score_collector.rs +++ b/src/collector/top_score_collector.rs @@ -23,13 +23,10 @@ use std::fmt; /// is `O(n log K)`. /// /// ```rust -/// #[macro_use] -/// extern crate tantivy; -/// use tantivy::DocAddress; -/// use tantivy::schema::{Schema, TEXT}; -/// use tantivy::{Index, Result}; /// use tantivy::collector::TopDocs; /// use tantivy::query::QueryParser; +/// use tantivy::schema::{Schema, TEXT}; +/// use tantivy::{doc, DocAddress, Index, Result}; /// /// # fn main() { example().unwrap(); } /// fn example() -> Result<()> { @@ -87,10 +84,8 @@ impl TopDocs { /// Set top-K to rank documents by a given fast field. /// /// ```rust - /// #[macro_use] - /// extern crate tantivy; /// # use tantivy::schema::{Schema, FAST, TEXT}; - /// # use tantivy::{Index, Result, DocAddress}; + /// # use tantivy::{doc, Index, Result, DocAddress}; /// # use tantivy::query::{Query, QueryParser}; /// use tantivy::Searcher; /// use tantivy::collector::TopDocs; @@ -197,10 +192,8 @@ impl TopDocs { /// learning-to-rank model over various features /// /// ```rust - /// #[macro_use] - /// extern crate tantivy; /// # use tantivy::schema::{Schema, FAST, TEXT}; - /// # use tantivy::{Index, DocAddress, DocId, Score}; + /// # use tantivy::{doc, Index, DocAddress, DocId, Score}; /// # use tantivy::query::QueryParser; /// use tantivy::SegmentReader; /// use tantivy::collector::TopDocs; @@ -302,10 +295,8 @@ impl TopDocs { /// # Example /// /// ```rust - /// # #[macro_use] - /// # extern crate tantivy; /// # use tantivy::schema::{Schema, FAST, TEXT}; - /// # use tantivy::{Index, DocAddress, DocId}; + /// # use tantivy::{doc, Index, DocAddress, DocId}; /// # use tantivy::query::QueryParser; /// use tantivy::SegmentReader; /// use tantivy::collector::TopDocs; diff --git a/src/indexer/index_writer.rs b/src/indexer/index_writer.rs index 5210281..bfbd1bb 100644 --- a/src/indexer/index_writer.rs +++ b/src/indexer/index_writer.rs @@ -450,12 +450,10 @@ impl IndexWriter { /// by clearing and resubmitting necessary documents /// /// ```rust - /// #[macro_use] - /// extern crate tantivy; - /// use tantivy::query::QueryParser; /// use tantivy::collector::TopDocs; + /// use tantivy::query::QueryParser; /// use tantivy::schema::*; - /// use tantivy::Index; + /// use tantivy::{doc, Index}; /// /// fn main() -> tantivy::Result<()> { /// let mut schema_builder = Schema::builder(); @@ -11,21 +11,12 @@ //! Think `Lucene`, but in Rust. //! //! ```rust - -//! # extern crate tempfile; -//! # -//! #[macro_use] -//! extern crate tantivy; -//! -//! // ... -//! //! # use std::path::Path; //! # use tempfile::TempDir; -//! # use tantivy::Index; -//! # use tantivy::schema::*; -//! # use tantivy::{Score, DocAddress}; //! # use tantivy::collector::TopDocs; //! # use tantivy::query::QueryParser; +//! # use tantivy::schema::*; +//! # use tantivy::{doc, DocAddress, Index, Score}; //! # //! # fn main() { //! # // Let's create a temporary directory for the diff --git a/src/macros.rs b/src/macros.rs index 640a70c..973111b 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -22,11 +22,9 @@ /// /// # Example /// -/// ``` -/// #[macro_use] -/// extern crate tantivy; -/// +/// ```rust /// use tantivy::schema::{Schema, TEXT, FAST}; +/// use tantivy::doc; /// /// //... /// diff --git a/src/query/fuzzy_query.rs b/src/query/fuzzy_query.rs index 156d7c3..25396ed 100644 --- a/src/query/fuzzy_query.rs +++ b/src/query/fuzzy_query.rs @@ -28,12 +28,10 @@ static LEV_BUILDER: Lazy<HashMap<(u8, bool), LevenshteinAutomatonBuilder>> = Laz /// containing a specific term that is within /// Levenshtein distance /// ```rust -/// #[macro_use] -/// extern crate tantivy; -/// use tantivy::schema::{Schema, TEXT}; -/// use tantivy::{Index, Result, Term}; /// use tantivy::collector::{Count, TopDocs}; /// use tantivy::query::FuzzyTermQuery; +/// use tantivy::schema::{Schema, TEXT}; +/// use tantivy::{doc, Index, Result, Term}; /// /// # fn main() { example().unwrap(); } /// fn example() -> Result<()> { diff --git a/src/query/range_query.rs b/src/query/range_query.rs index e9f034e..a8f6d26 100644 --- a/src/query/range_query.rs +++ b/src/query/range_query.rs @@ -38,14 +38,10 @@ fn map_bound<TFrom, TTo, Transform: Fn(&TFrom) -> TTo>( /// # Example /// /// ```rust -/// -/// # #[macro_use] -/// # extern crate tantivy; -/// # use tantivy::Index; -/// # use tantivy::schema::{Schema, INDEXED}; /// # use tantivy::collector::Count; -/// # use tantivy::Result; /// # use tantivy::query::RangeQuery; +/// # use tantivy::schema::{Schema, INDEXED}; +/// # use tantivy::{doc, Index, Result}; /// # /// # fn run() -> Result<()> { /// # let mut schema_builder = Schema::builder(); diff --git a/src/query/regex_query.rs b/src/query/regex_query.rs index 3296a8d..9b008bc 100644 --- a/src/query/regex_query.rs +++ b/src/query/regex_query.rs @@ -14,12 +14,10 @@ use tantivy_fst::Regex; /// Levenshtein distance /// /// ```rust -/// #[macro_use] -/// extern crate tantivy; -/// use tantivy::schema::{Schema, TEXT}; -/// use tantivy::{Index, Result, Term}; /// use tantivy::collector::Count; /// use tantivy::query::RegexQuery; +/// use tantivy::schema::{Schema, TEXT}; +/// use tantivy::{doc, Index, Result, Term}; /// /// # fn main() { example().unwrap(); } /// fn example() -> Result<()> { diff --git a/src/query/term_query/term_query.rs b/src/query/term_query/term_query.rs index 486ab59..6415293 100644 --- a/src/query/term_query/term_query.rs +++ b/src/query/term_query/term_query.rs @@ -20,12 +20,10 @@ use std::fmt; /// * `field norm` - number of tokens in the field. /// /// ```rust -/// #[macro_use] -/// extern crate tantivy; -/// use tantivy::schema::{Schema, TEXT, IndexRecordOption}; -/// use tantivy::{Index, Result, Term}; /// use tantivy::collector::{Count, TopDocs}; /// use tantivy::query::TermQuery; +/// use tantivy::schema::{Schema, TEXT, IndexRecordOption}; +/// use tantivy::{doc, Index, Result, Term}; /// /// # fn main() { example().unwrap(); } /// fn example() -> Result<()> { diff --git a/src/snippet/mod.rs b/src/snippet/mod.rs index 1ecba1c..1f602c9 100644 --- a/src/snippet/mod.rs +++ b/src/snippet/mod.rs @@ -213,11 +213,9 @@ fn select_best_fragment_combination(fragments: &[FragmentCandidate], text: &str) /// # Example /// /// ```rust -/// # #[macro_use] -/// # extern crate tantivy; -/// # use tantivy::Index; -/// # use tantivy::schema::{Schema, TEXT}; /// # use tantivy::query::QueryParser; +/// # use tantivy::schema::{Schema, TEXT}; +/// # use tantivy::{doc, Index}; /// use tantivy::SnippetGenerator; /// /// # fn main() -> tantivy::Result<()> { diff --git a/src/tokenizer/alphanum_only.rs b/src/tokenizer/alphanum_only.rs index 99d1d58..3c37c4c 100644 --- a/src/tokenizer/alphanum_only.rs +++ b/src/tokenizer/alphanum_only.rs @@ -1,6 +1,5 @@ //! # Example -//! ``` -//! extern crate tantivy; +//! ```rust //! use tantivy::tokenizer::*; //! //! # fn main() { diff --git a/src/tokenizer/mod.rs b/src/tokenizer/mod.rs index 7bdc021..fe50e6f 100644 --- a/src/tokenizer/mod.rs +++ b/src/tokenizer/mod.rs @@ -4,8 +4,7 @@ //! You must define in your schema which tokenizer should be used for //! each of your fields : //! -//! ``` -//! extern crate tantivy; +//! ```rust //! use tantivy::schema::*; //! //! # fn main() { @@ -65,8 +64,6 @@ //! For instance, the `en_stem` is defined as follows. //! //! ```rust -//! # extern crate tantivy; -//! //! use tantivy::tokenizer::*; //! //! # fn main() { @@ -80,8 +77,7 @@ //! Once your tokenizer is defined, you need to //! register it with a name in your index's [`TokenizerManager`](./struct.TokenizerManager.html). //! -//! ``` -//! # extern crate tantivy; +//! ```rust //! # use tantivy::schema::Schema; //! # use tantivy::tokenizer::*; //! # use tantivy::Index; @@ -101,8 +97,7 @@ //! //! # Example //! -//! ``` -//! extern crate tantivy; +//! ```rust //! use tantivy::schema::{Schema, IndexRecordOption, TextOptions, TextFieldIndexing}; //! use tantivy::tokenizer::*; //! use tantivy::Index; diff --git a/src/tokenizer/ngram_tokenizer.rs b/src/tokenizer/ngram_tokenizer.rs index 465e03a..22af50e 100644 --- a/src/tokenizer/ngram_tokenizer.rs +++ b/src/tokenizer/ngram_tokenizer.rs @@ -29,8 +29,7 @@ use super::{Token, TokenStream, Tokenizer}; /// /// # Example /// -/// ``` -/// # extern crate tantivy; +/// ```rust /// use tantivy::tokenizer::*; /// # fn main() { /// let tokenizer = NgramTokenizer::new(2, 3, false); diff --git a/src/tokenizer/remove_long.rs b/src/tokenizer/remove_long.rs index 2c63466..a81be9f 100644 --- a/src/tokenizer/remove_long.rs +++ b/src/tokenizer/remove_long.rs @@ -1,6 +1,5 @@ //! # Example -//! ``` -//! extern crate tantivy; +//! ```rust //! use tantivy::tokenizer::*; //! //! # fn main() { diff --git a/src/tokenizer/stop_word_filter.rs b/src/tokenizer/stop_word_filter.rs index bb4edd6..623388e 100644 --- a/src/tokenizer/stop_word_filter.rs +++ b/src/tokenizer/stop_word_filter.rs @@ -1,6 +1,5 @@ //! # Example -//! ``` -//! extern crate tantivy; +//! ```rust //! use tantivy::tokenizer::*; //! //! # fn main() { |