Skip to content

Commit 617acff

Browse files
committed
Add doctests for the traits.
1 parent 9cce85b commit 617acff

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ struct Rectangle {
5959
height: u32,
6060
}
6161
62-
impl Tldr for Rectangle {
62+
impl Tldr<String> for Rectangle {
6363
type Error = Box<dyn Error>;
6464
65-
fn what(&self, _ctx: &TldrContext) -> TldrResult<T> {
65+
fn what(&self, _ctx: &TldrContext) -> TldrResult<String> {
6666
Ok(Some(format!("A rectangle with a width of {} and a height of {}.", self.width, self.height)))
6767
}
6868
}

src/language.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use core::{fmt, str::FromStr};
55

66
/// ```rust
77
/// # use tldr_traits::TldrLanguage;
8+
/// let language = TldrLanguage::default(); // this is the same as...
89
/// let language = TldrLanguage::English;
910
/// ```
1011
#[non_exhaustive]

src/traits/tldr.rs

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

6+
/// ```rust
7+
/// # use tldr_traits::{Tldr, TldrContext, TldrResult};
8+
/// # use core::error::Error;
9+
/// struct Rectangle {
10+
/// width: u32,
11+
/// height: u32,
12+
/// }
13+
///
14+
/// impl Tldr<String> for Rectangle {
15+
/// type Error = Box<dyn Error>;
16+
///
17+
/// fn what(&self, _ctx: &TldrContext) -> TldrResult<String> {
18+
/// Ok(Some(format!("A rectangle with a width of {} and a height of {}.", self.width, self.height)))
19+
/// }
20+
/// }
21+
/// ```
22+
///
623
/// See: https://en.wikipedia.org/wiki/Five_Ws
724
/// See: https://en.wikipedia.org/wiki/Interrogative_word
825
pub trait Tldr<T = String> {

src/traits/to_tldr.rs

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

6+
/// ```rust
7+
/// # use tldr_traits::{Tldr, TldrSummary, ToTldr};
8+
/// struct Rectangle {
9+
/// width: u32,
10+
/// height: u32,
11+
/// }
12+
///
13+
/// impl ToTldr<String> for Rectangle {
14+
/// type Error = Box<dyn core::error::Error>;
15+
///
16+
/// fn to_tldr(&self) -> Box<dyn Tldr<String, Error = Self::Error>> {
17+
/// todo!() // FIXME
18+
/// }
19+
/// }
20+
/// ```
621
pub trait ToTldr<T = String> {
722
/// The associated error type.
823
///

0 commit comments

Comments
 (0)