~enan/wordnik-rs

ca2c0bc0c9b8b0e1701517f2b4774082fd6e7f6e — Enan Ajmain 1 year, 8 months ago 714bcce master v0.2.6
feat: support for wrapping prettified definition
2 files changed, 18 insertions(+), 10 deletions(-)

M Cargo.toml
M src/lib.rs
M Cargo.toml => Cargo.toml +2 -1
@@ 1,6 1,6 @@
[package]
name = "wordnik"
version = "0.2.5"
version = "0.2.6"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html


@@ 9,3 9,4 @@ edition = "2021"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
reqwest = { version = "0.11.12", features = ["json", "blocking", "cookies"] }
textwrap = { version = "0.16.0" }

M src/lib.rs => src/lib.rs +16 -9
@@ 138,15 138,17 @@ impl Wordnik {
  ///
  /// # Arguments
  ///
  /// * `word` - The word whose meaning you want
  /// * `dicts` - The dictionaries you want to use.
  ///             Pass an empty vector if you want to use all.
  ///             The available dictionaries are:
  ///               - "ahd-5": American Heritage Dictionary
  ///               - "century": The Century Dictionary
  ///               - "gcide": GNU version of the Collaborative International Dictionary of English
  ///               - "wiktionary": Wiktionary
  ///               - "wordnet": WordNet 3.0 Copyright 2006 by Princeton University
  /// * `word`      - The word whose meaning you want.
  /// * `textwidth` - The column at which to wrap the text.
  ///                 Pass 0 if you want want to wrap at all.
  /// * `dicts`     - The dictionaries you want to use.
  ///                 Pass an empty vector if you want to use all.
  ///                 The available dictionaries are:
  ///                   - "ahd-5": American Heritage Dictionary
  ///                   - "century": The Century Dictionary
  ///                   - "gcide": GNU version of the Collaborative International Dictionary of English
  ///                   - "wiktionary": Wiktionary
  ///                   - "wordnet": WordNet 3.0 Copyright 2006 by Princeton University
  ///
  /// # Examples
  ///


@@ 164,6 166,7 @@ impl Wordnik {
  pub fn get_definitions_pretty(
    &self,
    word: &str,
    textwidth: usize,
    dicts: Vec<&str>,
  ) -> Result<String, Box<dyn std::error::Error>> {
    let definitions = self.get_definitions(word)?;


@@ 194,6 197,10 @@ impl Wordnik {
        + "\n";
    }

    if textwidth != 0 {
      s = textwrap::fill(s.as_str(), textwidth);
    }

    Ok(s)
  }
}