Skip to content

Commit a78ef5d

Browse files
committed
Draft some TL;DR abstractions.
1 parent b349b2a commit a78ef5d

File tree

7 files changed

+225
-2
lines changed

7 files changed

+225
-2
lines changed

README.md

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,20 @@
55
[![Package](https://img.shields.io/crates/v/tldr-traits)](https://crates.io/crates/tldr-traits)
66
[![Documentation](https://docs.rs/tldr-traits/badge.svg)](https://docs.rs/tldr-traits)
77

8-
🚧 _We are building in public. This is presently under heavy construction._
8+
[Rust] abstractions for [TL;DR] summarization.
99

1010
## ✨ Features
1111

12+
- Provides the trait [`Tldr`] to generate TL;DR summaries.
13+
- Provides the trait [`ToTldr`] to convert objects into TL;DR summaries.
14+
- Supports TL;DR generation for multiple natural languages.
15+
- Zero required dependencies, only optional integrations.
1216
- Adheres to the Rust API Guidelines in its [naming conventions].
1317
- 100% free and unencumbered public domain software.
1418

1519
## 🛠️ Prerequisites
1620

17-
- [Rust](https://rust-lang.org) 1.85+ (2024 edition)
21+
- [Rust] 1.85+ (2024 edition)
1822

1923
## ⬇️ Installation
2024

@@ -24,6 +28,20 @@
2428
cargo add tldr-traits --rename tldr
2529
```
2630

31+
### Installation in `Cargo.toml` (with all features enabled)
32+
33+
```toml
34+
[dependencies]
35+
tldr = { version = "0", package = "tldr-traits" }
36+
```
37+
38+
### Installation in `Cargo.toml` (with only specific features enabled)
39+
40+
```toml
41+
[dependencies]
42+
tldr = { version = "0", package = "tldr-traits", default-features = false, features = ["serde"] }
43+
```
44+
2745
## 👉 Examples
2846

2947
### Importing the Library
@@ -32,6 +50,52 @@ cargo add tldr-traits --rename tldr
3250
use tldr::*;
3351
```
3452

53+
## 📚 Reference
54+
55+
### [`ToTldr`]
56+
57+
```rust
58+
pub trait ToTldr {
59+
fn to_tldr(&self) -> Box<dyn Tldr>;
60+
}
61+
```
62+
63+
### [`Tldr`]
64+
65+
```rust
66+
pub trait Tldr {
67+
fn who(&self, ctx: &TldrContext) -> Option<String>;
68+
fn what(&self, ctx: &TldrContext) -> Option<String>;
69+
fn when(&self, ctx: &TldrContext) -> Option<String>;
70+
fn r#where(&self, ctx: &TldrContext) -> Option<String>;
71+
fn why(&self, ctx: &TldrContext) -> Option<String>;
72+
fn whence(&self, ctx: &TldrContext) -> Option<String>;
73+
fn how(&self, ctx: &TldrContext) -> Option<String>;
74+
}
75+
```
76+
77+
### [`TldrSummary`]
78+
79+
```rust
80+
pub struct TldrSummary {
81+
pub who: Option<String>,
82+
pub what: Option<String>,
83+
pub when: Option<String>,
84+
pub r#where: Option<String>,
85+
pub why: Option<String>,
86+
pub whence: Option<String>,
87+
pub how: Option<String>,
88+
}
89+
```
90+
91+
### [`TldrContext`]
92+
93+
```rust
94+
pub struct TldrContext {
95+
pub language: String,
96+
}
97+
```
98+
3599
## 👨‍💻 Development
36100

37101
```bash
@@ -46,4 +110,11 @@ git clone https://github.com/dryrust/tldr.rs.git
46110
[![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)
47111
[![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)
48112

113+
[Rust]: https://rust-lang.org
114+
[TL;DR]: https://en.wikipedia.org/wiki/TL;DR
49115
[naming conventions]: https://rust-lang.github.io/api-guidelines/naming.html
116+
117+
[`Tldr`]: #
118+
[`TldrContext`]: #
119+
[`TldrSummary`]: #
120+
[`ToTldr`]: #

src/context.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// This is free and unencumbered software released into the public domain.
2+
3+
use alloc::string::String;
4+
use core::str::FromStr;
5+
6+
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
7+
pub struct TldrContext {
8+
pub language: String,
9+
}
10+
11+
impl FromStr for TldrContext {
12+
type Err = ();
13+
14+
fn from_str(input: &str) -> Result<Self, Self::Err> {
15+
Ok(TldrContext {
16+
language: input.into(),
17+
})
18+
}
19+
}

src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,12 @@
1010
pub struct ReadmeDoctests;
1111

1212
extern crate alloc;
13+
14+
mod context;
15+
pub use context::*;
16+
17+
mod summary;
18+
pub use summary::*;
19+
20+
mod traits;
21+
pub use traits::*;

src/summary.rs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// This is free and unencumbered software released into the public domain.
2+
3+
use crate::{Tldr, TldrContext, ToTldr};
4+
use alloc::{boxed::Box, string::String};
5+
6+
/// See: https://en.wikipedia.org/wiki/Five_Ws
7+
/// See: https://en.wikipedia.org/wiki/Interrogative_word
8+
#[derive(Clone, Debug)]
9+
pub struct TldrSummary {
10+
/// See: https://en.wiktionary.org/wiki/who
11+
pub who: Option<String>,
12+
13+
/// See: https://en.wiktionary.org/wiki/what
14+
pub what: Option<String>,
15+
16+
/// See: https://en.wiktionary.org/wiki/when
17+
pub when: Option<String>,
18+
19+
/// See: https://en.wiktionary.org/wiki/where
20+
pub r#where: Option<String>,
21+
22+
/// See: https://en.wiktionary.org/wiki/why
23+
pub why: Option<String>,
24+
25+
/// See: https://en.wiktionary.org/wiki/whence
26+
pub whence: Option<String>,
27+
28+
/// See: https://en.wiktionary.org/wiki/how
29+
pub how: Option<String>,
30+
}
31+
32+
impl ToTldr for TldrSummary {
33+
fn to_tldr(&self) -> Box<dyn Tldr> {
34+
Box::new(self.clone())
35+
}
36+
}
37+
38+
impl Tldr for TldrSummary {
39+
fn who(&self, _ctx: &TldrContext) -> Option<String> {
40+
self.who.clone()
41+
}
42+
43+
fn what(&self, _ctx: &TldrContext) -> Option<String> {
44+
self.what.clone()
45+
}
46+
47+
fn when(&self, _ctx: &TldrContext) -> Option<String> {
48+
self.when.clone()
49+
}
50+
51+
fn r#where(&self, _ctx: &TldrContext) -> Option<String> {
52+
self.r#where.clone()
53+
}
54+
55+
fn why(&self, _ctx: &TldrContext) -> Option<String> {
56+
self.why.clone()
57+
}
58+
59+
fn whence(&self, _ctx: &TldrContext) -> Option<String> {
60+
self.whence.clone()
61+
}
62+
63+
fn how(&self, _ctx: &TldrContext) -> Option<String> {
64+
self.how.clone()
65+
}
66+
}

src/traits.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// This is free and unencumbered software released into the public domain.
2+
3+
mod tldr;
4+
pub use tldr::*;
5+
6+
mod to_tldr;
7+
pub use to_tldr::*;

src/traits/tldr.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// This is free and unencumbered software released into the public domain.
2+
3+
use crate::TldrContext;
4+
use alloc::string::String;
5+
6+
/// See: https://en.wikipedia.org/wiki/Five_Ws
7+
/// See: https://en.wikipedia.org/wiki/Interrogative_word
8+
pub trait Tldr {
9+
/// See: https://en.wiktionary.org/wiki/who
10+
fn who(&self, _ctx: &TldrContext) -> Option<String> {
11+
None
12+
}
13+
14+
/// See: https://en.wiktionary.org/wiki/what
15+
fn what(&self, _ctx: &TldrContext) -> Option<String> {
16+
None
17+
}
18+
19+
/// See: https://en.wiktionary.org/wiki/when
20+
fn when(&self, _ctx: &TldrContext) -> Option<String> {
21+
None
22+
}
23+
24+
/// See: https://en.wiktionary.org/wiki/where
25+
fn r#where(&self, _ctx: &TldrContext) -> Option<String> {
26+
None
27+
}
28+
29+
/// See: https://en.wiktionary.org/wiki/why
30+
fn why(&self, _ctx: &TldrContext) -> Option<String> {
31+
None
32+
}
33+
34+
/// See: https://en.wiktionary.org/wiki/whence
35+
fn whence(&self, _ctx: &TldrContext) -> Option<String> {
36+
None
37+
}
38+
39+
/// See: https://en.wiktionary.org/wiki/how
40+
fn how(&self, _ctx: &TldrContext) -> Option<String> {
41+
None
42+
}
43+
}

src/traits/to_tldr.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// This is free and unencumbered software released into the public domain.
2+
3+
use crate::Tldr;
4+
use alloc::boxed::Box;
5+
6+
pub trait ToTldr {
7+
fn to_tldr(&self) -> Box<dyn Tldr>;
8+
}

0 commit comments

Comments
 (0)