Struct RequestBuilder

Source
pub struct RequestBuilder<'a> { /* private fields */ }
Expand description

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

Implementations§

Source§

impl<'a> RequestBuilder<'a>

Source

pub fn means_like(self, word: &str) -> Self

Sets a query parameter for words which have a similar meaning to the given word

Source

pub fn sounds_like(self, word: &str) -> Self

Sets a query parameter for words which sound similar to the given word

Source

pub fn spelled_like(self, word: &str) -> Self

Sets a query parameter for words which have a similar spelling to the given word. This parameter allows for wildcard charcters with ‘?’ matching a single letter and ‘*’ matching any number of letters

Source

pub fn related(self, rel_type: RelatedType, word: &str) -> Self

Sets a query parameter for words which are related to the given word. The various options for relations are given in the RelatedType enum. See its documentation for more information on the options. Note that this is currently not available for the Spanish vocabulary set

Source

pub fn add_topic(self, word: &str) -> Self

Sets a query parameter for words which fall under the topic of the given word. Multiple topics can be specified at once, however requests are limited to five topics and as such any specified over this limit will be ignored

Source

pub fn left_context(self, word: &str) -> Self

Sets a query parameter to refer to the word directly before the main query term

Source

pub fn right_context(self, word: &str) -> Self

Sets a query parameter to refer to the word directly after the main query term

Source

pub fn max_results(self, maximum: u16) -> Self

The maximum number of results that should be returned. By default this is set to 100 and it can be increased to a maximum of 1000. This parameter is also allowed for the “suggest” endpoint

Source

pub fn meta_data(self, flag: MetaDataFlag) -> Self

Sets a metadata flag to specify data returned with each word. The various options for flags are given in the MetaDataFlag enum. See its documentation for more information on the options

Source

pub fn hint_string(self, hint: &str) -> Self

Sets the hint string for the “suggest” endpoint. Note that this is not allowed for the “words” endpoint

Source

pub fn build(&self) -> Result<Request<'_>>

Converts the RequestBuilder into a Request which can be executed by calling the send() method on it. This method will return an error if any of the given parameters have not been used correctly or the underlying call to reqwest to build the request fails

Source

pub async fn send(&self) -> Result<Response>

A convenience method to build and send the request in one step. The resulting response can be parsed with its list() method

Source

pub async fn list(&self) -> Result<Vec<WordElement>>

A convenience method to build and send the request as well as parse the json in one step

Trait Implementations§

Source§

impl<'a> Debug for RequestBuilder<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for RequestBuilder<'a>

§

impl<'a> !RefUnwindSafe for RequestBuilder<'a>

§

impl<'a> Send for RequestBuilder<'a>

§

impl<'a> Sync for RequestBuilder<'a>

§

impl<'a> Unpin for RequestBuilder<'a>

§

impl<'a> !UnwindSafe for RequestBuilder<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,