[][src]Crate datamuse_api_wrapper

Datamuse Api Wrapper

This library provides an unofficial wrapper around the Datamuse api for use in rust projects. The Datamuse api allows users to retrieve lists of words from different vocabulary lists based on a large number of different parameters. Additionally, it can be used to retrieve words based on a short string of letters, allowing for autocomplete functionality. Currently, the api does not require an api key and can be used to make up to 100,000 requests per day after which the requests may be rate-limited (for higher usage see website). If you use this api you should make reference to the Datamuse api in your project. For more information see the official documentation at https://www.datamuse.com/api/

Examples

Words Endpoint

extern crate tokio;
extern crate datamuse_api_wrapper;
use datamuse_api_wrapper::{ DatamuseClient, Vocabulary, EndPoint, RelatedType };

#[tokio::main]
async fn main() -> datamuse_api_wrapper::Result<()> {
    let client = DatamuseClient::new();
    let request = client.new_query(Vocabulary::English, EndPoint::Words)
        .means_like("breakfast") // The words we're looking for are related to "breakfast"
        .related(RelatedType::Rhyme, "grape"); // and rhyme with "grape"
    let word_list = request.list().await?; // Get the list of words from the api

    assert_eq!("crepe", word_list[0].word); // "crepe" is the only result as of writing this

    Ok(())
}

Suggest EndPoint

extern crate tokio;
extern crate datamuse_api_wrapper;
use datamuse_api_wrapper::{ DatamuseClient, Vocabulary, EndPoint };

#[tokio::main]
async fn main() -> datamuse_api_wrapper::Result<()> {
    let client = DatamuseClient::new();
    let request = client.new_query(Vocabulary::English, EndPoint::Suggest)
        .hint_string("hello wor") // The user has alread typed in "hello wor"
        .max_results(2); // We only want the first 2 results to be returned

    let request = request.build()?; // Build the request
    let response = request.send().await?; // Send the request
    let word_list = response.list()?; // Parse the response into a word_list

    assert_eq!("hello world", word_list[0].word); // "hello world" is the first result as of writing this

    Ok(())
}

Structs

DatamuseClient

This struct represents the client which can be used to make requests to the Datamuse api. Requests can be created using the new_query() method

Definition

A struct representing a word definition

Request

This struct represents a built request that can be sent using the send() method

RequestBuilder

Use this struct to build requests to send to the Datamuse api. This request can be sent either by building it into a Request with build() and then using the send() method on the resulting Request or using send() to send it directly. Note that not all parameters can be used for each vocabulary and endpoint

Response

A struct representing a response from a request. This can be parsed into a word list using the list() method

WordElement

This struct represents each word and its associated data in the response. It is constructed when parsing a Response with the method list(). Note that all optional values can still be None even if the proper flag is set

Enums

EndPoint

This enum represents the different endpoints of the Datamuse api. The "words" endpoint returns word lists based on a set of parameters, whereas the "suggest" endpoint returns suggestions for words based on a hint string (autocomplete). For more detailed information visit the Datamuse website

Error

An enum representing the different kind of Errors that can be returned within the library

MetaDataFlag

This enum represents the various flags which can be set for retrieving metadata for each word. These metadata flags can be combined in any manner. Each is shortly described below

PartOfSpeech

An enum representing all possible parts of speech returned from the api

PronunciationFormat

This enum represents the ways pronunciations returned by the "Pronunciation" metadata flag can be given

RelatedType

This enum represents the different possibilites the "Related" parameter can take. These parameters can be combined in any possible configuration, although very specific queries can limit results. Each option is shortly explained below. For more detailed information for each type visit the Datamuse website

Vocabulary

This enum represents the different vocabulary lists which can be used as a source for the requests. There are currently two language options (English or Spanish) and an alternative English option from wikipedia. For more detailed information visit the Datamuse website

Type Definitions

Result

A type alias for Results with the library Error type