Request

Struct Request 

Source
#[non_exhaustive]
pub struct Request<'source> {
Show 14 fields pub text: Option<Cow<'source, str>>, pub data: Option<Data<'source>>, pub language: String, pub username: Option<String>, pub api_key: Option<String>, pub dicts: Option<Vec<String>>, pub mother_tongue: Option<String>, pub preferred_variants: Option<Vec<String>>, pub enabled_rules: Option<Vec<String>>, pub disabled_rules: Option<Vec<String>>, pub enabled_categories: Option<Vec<String>>, pub disabled_categories: Option<Vec<String>>, pub enabled_only: bool, pub level: Level,
}
Expand description

LanguageTool POST check request.

The main feature - check a text with LanguageTool for possible style and grammar issues.

The structure below tries to follow as closely as possible the JSON API described here.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§text: Option<Cow<'source, str>>

The text to be checked. This or ‘data’ is required.

§data: Option<Data<'source>>

The text to be checked, given as a JSON document that specifies what’s text and what’s markup. This or ‘text’ is required.

Markup will be ignored when looking for errors. Example text:

A <b>test</b>

JSON for the example text:

{"annotation":[
 {"text": "A "},
 {"markup": "<b>"},
 {"text": "test"},
 {"markup": "</b>"}
]}

If you have markup that should be interpreted as whitespace, like <p> in HTML, you can have it interpreted like this:

{"markup": "<p>", "interpretAs": "\n\n"}

The ‘data’ feature is not limited to HTML or XML, it can be used for any kind of markup. Entities will need to be expanded in this input.

§language: String

A language code like en-US, de-DE, fr, or auto to guess the language automatically (see preferredVariants below).

For languages with variants (English, German, Portuguese) spell checking will only be activated when you specify the variant, e.g. en-GB instead of just en.

§username: Option<String>

Set to get Premium API access: Your username/email as used to log in at languagetool.org.

§api_key: Option<String>

Set to get Premium API access: your API key (see https://languagetool.org/editor/settings/api).

§dicts: Option<Vec<String>>

Comma-separated list of dictionaries to include words from; uses special default dictionary if this is unset.

§mother_tongue: Option<String>

A language code of the user’s native language, enabling false friends checks for some language pairs.

§preferred_variants: Option<Vec<String>>

Comma-separated list of preferred language variants.

The language detector used with language=auto can detect e.g. English, but it cannot decide whether British English or American English is used. Thus this parameter can be used to specify the preferred variants like en-GB and de-AT. Only available with language=auto. You should set variants for at least German and English, as otherwise the spell checking will not work for those, as no spelling dictionary can be selected for just en or de.

§enabled_rules: Option<Vec<String>>

IDs of rules to be enabled, comma-separated.

§disabled_rules: Option<Vec<String>>

IDs of rules to be disabled, comma-separated.

§enabled_categories: Option<Vec<String>>

IDs of categories to be enabled, comma-separated.

§disabled_categories: Option<Vec<String>>

IDs of categories to be disabled, comma-separated.

§enabled_only: bool

If true, only the rules and categories whose IDs are specified with enabledRules or enabledCategories are enabled.

§level: Level

If set to picky, additional rules will be activated, i.e. rules that you might only find useful when checking formal text.

Implementations§

Source§

impl<'source> Request<'source>

Source

pub fn new() -> Self

Create a new empty request with language set to "auto".

Source

pub fn with_text<T: Into<Cow<'source, str>>>(self, text: T) -> Self

Set the text to be checked and remove potential data field.

Source

pub fn with_data(self, data: Data<'source>) -> Self

Set the data to be checked and remove potential text field.

Source

pub fn with_data_str(self, data: &str) -> Result<Self>

Set the data (obtained from string) to be checked and remove potential text field

Source

pub fn with_language(self, language: String) -> Self

Set the language of the text / data.

Source

pub fn try_get_text(&self) -> Result<Cow<'source, str>>

Return the text within the request.

§Errors

If both self.text and self.data are None. If any data annotation does not contain text or markup.

Source

pub fn get_text(&self) -> Cow<'source, str>

Return a copy of the text within the request. Call Request::try_get_text but panic on error.

§Panics

If both self.text and self.data are None. If any data annotation does not contain text or markup.

Source

pub fn try_split(self, n: usize, pat: &str) -> Result<Vec<Self>>

Split this request into multiple, using split_len function to split text.

§Errors

If self.text is None and self.data is None.

Source

pub fn split(self, n: usize, pat: &str) -> Vec<Self>

Split this request into multiple, using split_len function to split text. Call Request::try_split but panic on error.

§Panics

If self.text is none.

Trait Implementations§

Source§

impl<'source> Clone for Request<'source>

Source§

fn clone(&self) -> Request<'source>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'source> Debug for Request<'source>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'source> Default for Request<'source>

Source§

fn default() -> Request<'source>

Returns the “default value” for a type. Read more
Source§

impl From<CliRequest> for Request<'_>

Available on crate feature cli only.
Source§

fn from(val: CliRequest) -> Self

Converts to this type from the input type.
Source§

impl<'source> Hash for Request<'source>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'source> IntoStatic for Request<'source>

Source§

type Static = Request<'static>

Source§

fn into_static(self) -> Request<'static>

Source§

impl<'source> PartialEq for Request<'source>

Source§

fn eq(&self, other: &Request<'source>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'source> Serialize for Request<'source>

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<'source> Eq for Request<'source>

Source§

impl<'source> StructuralPartialEq for Request<'source>

Auto Trait Implementations§

§

impl<'source> Freeze for Request<'source>

§

impl<'source> RefUnwindSafe for Request<'source>

§

impl<'source> Send for Request<'source>

§

impl<'source> Sync for Request<'source>

§

impl<'source> Unpin for Request<'source>

§

impl<'source> UnwindSafe for Request<'source>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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, 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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,