Add documentation

This commit is contained in:
Pierre HUBERT 2022-12-19 12:30:33 +01:00
parent d52bdbde8f
commit af6016ae96

View File

@ -1,3 +1,39 @@
//! # Grammalecte Rust Client
//!
//! This crate is a Rust client to the Grammalecte server API.
//!
//! Grammalecte is an Open Source software that allows to do
//! french spell-checking.
//!
//! ## Integrated server
//! The optional feature `embedded-server` allows you to spin up an
//! temporary web server that will act as Grammalecte backend, instead
//! of targetting an existing instance:
//!
//! ```rust,no_run
//! use grammalecte_client::GrammalecteClient;
//!
//! let msg = "Les ange sont inssuportables!";
//! let res = GrammalecteClient::start_server()
//! .unwrap()
//! .spell_check(msg)
//! .await
//! .unwrap();
//! println!("RESULT = {:#?}", res);
//! ```
//!
//! ## Suggestion
//! You can also ask Grammalecte to give you valid alternatives words:
//! ```rust,no_run
//! let res = GrammalecteClient::start_server()
//! .unwrap()
//! .suggest("bonjou")
//! .await
//! .unwrap();
//! assert!(res.suggestions.contains(&"bonjour".to_string()));
//! println!("RESULT = {:#?}", res);
//! ```
#[cfg(feature = "embedded-server")] #[cfg(feature = "embedded-server")]
use crate::server::EmbeddedServer; use crate::server::EmbeddedServer;
use std::collections::HashMap; use std::collections::HashMap;
@ -150,6 +186,7 @@ pub enum GramOpt {
} }
impl GramOpt { impl GramOpt {
/// Get the technical ID of the Grammalecte option
pub fn id(&self) -> &'static str { pub fn id(&self) -> &'static str {
match self { match self {
GramOpt::SignesTypographiques => "typo", GramOpt::SignesTypographiques => "typo",
@ -208,6 +245,7 @@ pub struct CheckResult {
pub paragraphs: Vec<Paragraph>, pub paragraphs: Vec<Paragraph>,
} }
/// Check spell result of a given paragraph
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct Paragraph { pub struct Paragraph {
#[serde(rename = "iParagraph")] #[serde(rename = "iParagraph")]
@ -218,6 +256,7 @@ pub struct Paragraph {
pub spelling: Vec<SpellingError>, pub spelling: Vec<SpellingError>,
} }
/// Single grammar error
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct GrammarError { pub struct GrammarError {
#[serde(rename = "nStart")] #[serde(rename = "nStart")]
@ -240,6 +279,7 @@ pub struct GrammarError {
pub url: String, pub url: String,
} }
/// Spelling error information
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct SpellingError { pub struct SpellingError {
pub i: usize, pub i: usize,
@ -253,11 +293,13 @@ pub struct SpellingError {
pub error_type: String, pub error_type: String,
} }
/// Response to a suggestion request
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct SuggestResult { pub struct SuggestResult {
suggestions: Vec<String>, suggestions: Vec<String>,
} }
/// The Grammalecte client itself
pub struct GrammalecteClient { pub struct GrammalecteClient {
base_url: String, base_url: String,