Skip to content

Commit 15cf695

Browse files
committed
Improve the documentation.
1 parent eeff8b4 commit 15cf695

File tree

7 files changed

+58
-6
lines changed

7 files changed

+58
-6
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
- Provides the [`Tldr`](#tldr) trait for generating TL;DR summaries.
1313
- Provides the [`ToTldr`](#totldr) trait for converting objects into TL;DR
1414
summaries.
15-
- Supports TL;DR generation for multiple natural languages.
16-
- Zero required dependencies, only optional integrations.
15+
- Supports multilingual TL;DR generation while defaulting to English.
16+
- Zero required dependencies, only optional integrations with [Serde] & [Bon].
1717
- Adheres to the Rust API Guidelines in its [naming conventions].
1818
- 100% free and unencumbered public domain software.
1919

@@ -153,7 +153,9 @@ git clone https://github.com/dryrust/tldr.rs.git
153153
[![Share on Facebook](https://img.shields.io/badge/share%20on-fb-1976D2?logo=facebook)](https://www.facebook.com/sharer/sharer.php?u=https://github.com/dryrust/tldr.rs)
154154
[![Share on LinkedIn](https://img.shields.io/badge/share%20on-linkedin-3949AB?logo=linkedin)](https://www.linkedin.com/sharing/share-offsite/?url=https://github.com/dryrust/tldr.rs)
155155

156+
[Bon]: https://crates.io/crates/bon
156157
[Rust]: https://rust-lang.org
158+
[Serde]: https://crates.io/crates/serde
157159
[TL;DR]: https://en.wikipedia.org/wiki/TL;DR
158160
[five Ws]: https://en.wikipedia.org/wiki/Five_Ws
159161
[naming conventions]: https://rust-lang.github.io/api-guidelines/naming.html

src/context.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33
use crate::TldrLanguage;
44
use core::str::FromStr;
55

6+
/// A context used when generating TL;DR summaries.
7+
///
8+
/// # Examples
9+
///
610
/// ```rust
711
/// # use tldr_traits::TldrContext;
812
/// let context = TldrContext::builder()
913
/// .language("en")
1014
/// .build();
1115
/// ```
16+
#[non_exhaustive]
1217
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq)]
1318
#[cfg_attr(feature = "builder", derive(bon::Builder))]
1419
#[cfg_attr(feature = "builder", builder(on(TldrLanguage, into)))]

src/language.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
use alloc::string::String;
44
use core::{fmt, str::FromStr};
55

6+
/// The language that a TL;DR summary is written in.
7+
///
8+
/// # Examples
9+
///
610
/// ```rust
711
/// # use tldr_traits::TldrLanguage;
812
/// let language = TldrLanguage::default(); // this is the same as...

src/result.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
use alloc::{boxed::Box, string::String};
44
use core::error::Error;
55

6+
/// The result type used throughout the library.
67
pub type TldrResult<T = String, E = Box<dyn Error>> = Result<Option<T>, E>;

src/summary.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ use crate::{Tldr, TldrContext, TldrResult, ToTldr};
44
use alloc::{boxed::Box, string::String};
55
use core::fmt::Debug;
66

7+
/// An owned TL;DR summary.
8+
///
9+
/// # Examples
10+
///
711
/// ```rust
812
/// # use tldr_traits::TldrSummary;
913
/// let summary: TldrSummary<String> = TldrSummary::builder()
@@ -17,8 +21,9 @@ use core::fmt::Debug;
1721
/// .build();
1822
/// ```
1923
///
20-
/// See: https://en.wikipedia.org/wiki/Five_Ws
21-
/// See: https://en.wikipedia.org/wiki/Interrogative_word
24+
/// See: [en.wikipedia.org/wiki/Five_Ws](https://en.wikipedia.org/wiki/Five_Ws)
25+
///
26+
/// See: [en.wikipedia.org/wiki/Interrogative_word](https://en.wikipedia.org/wiki/Interrogative_word)
2227
#[derive(Clone, Debug, Default)]
2328
#[cfg_attr(feature = "builder", derive(bon::Builder))]
2429
#[cfg_attr(feature = "builder", builder(on(T, into)))]

src/traits/tldr.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
use crate::{TldrContext, TldrResult};
44
use alloc::string::String;
55

6+
/// A trait for generating a TL;DR summary.
7+
///
8+
/// # Examples
9+
///
10+
/// Implementing the `Tldr` trait for a custom type is simple:
11+
///
612
/// ```rust
713
/// # use tldr_traits::{Tldr, TldrContext, TldrResult};
814
/// # use core::error::Error;
@@ -20,8 +26,33 @@ use alloc::string::String;
2026
/// }
2127
/// ```
2228
///
23-
/// See: https://en.wikipedia.org/wiki/Five_Ws
24-
/// See: https://en.wikipedia.org/wiki/Interrogative_word
29+
/// Generally, you'd want to match on the context language to provide a
30+
/// localized response:
31+
///
32+
/// ```rust
33+
/// # use tldr_traits::{Tldr, TldrContext, TldrLanguage, TldrResult};
34+
/// # use core::error::Error;
35+
/// struct Rectangle {
36+
/// width: u32,
37+
/// height: u32,
38+
/// }
39+
///
40+
/// impl Tldr<String> for Rectangle {
41+
/// type Error = Box<dyn Error>;
42+
///
43+
/// fn what(&self, ctx: &TldrContext) -> TldrResult<String> {
44+
/// use TldrLanguage::*;
45+
/// Ok(match ctx.language {
46+
/// English => Some(format!("A rectangle with a width of {} and a height of {}.", self.width, self.height)),
47+
/// _ => None,
48+
/// })
49+
/// }
50+
/// }
51+
/// ```
52+
///
53+
/// See: [en.wikipedia.org/wiki/Five_Ws](https://en.wikipedia.org/wiki/Five_Ws)
54+
///
55+
/// See: [en.wikipedia.org/wiki/Interrogative_word](https://en.wikipedia.org/wiki/Interrogative_word)
2556
pub trait Tldr<T = String> {
2657
/// The associated error type.
2758
///

src/traits/to_tldr.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
use crate::Tldr;
44
use alloc::{boxed::Box, string::String};
55

6+
/// A trait for converting objects into TL;DR summaries.
7+
///
8+
/// # Examples
9+
///
610
/// ```rust
711
/// # use tldr_traits::{Tldr, TldrSummary, ToTldr};
812
/// struct Rectangle {

0 commit comments

Comments
 (0)