| Crates.io | tldr-traits |
| lib.rs | tldr-traits |
| version | 0.1.1 |
| created_at | 2025-08-04 11:01:54.762962+00 |
| updated_at | 2025-08-06 06:55:52.596865+00 |
| description | Abstractions for TL;DR summarization using the five Ws: who? what? when? where? why? |
| homepage | https://github.com/dryrust/tldr.rs |
| repository | https://github.com/dryrust/tldr.rs |
| max_upload_size | |
| id | 1780592 |
| size | 27,088 |
Rust abstractions for TL;DR summarization using the five Ws: who? what? when? where? why?
Tldr trait for generating TL;DR summaries.ToTldr trait for converting objects into TL;DR
summaries.cargo add tldr-traits --rename tldr
Cargo.toml (with all features enabled)[dependencies]
tldr = { version = "0", package = "tldr-traits" }
Cargo.toml (with only specific features enabled)[dependencies]
tldr = { version = "0", package = "tldr-traits", default-features = false, features = ["serde"] }
use tldr::{Tldr, TldrContext, TldrLanguage, TldrResult, TldrSummary, ToTldr};
struct Rectangle {
width: u32,
height: u32,
}
impl Tldr<String> for Rectangle {
type Error = Box<dyn Error>;
fn what(&self, _ctx: &TldrContext) -> TldrResult<String> {
Ok(Some(format!("A rectangle with a width of {} and a height of {}.", self.width, self.height)))
}
}
Tldrpub trait Tldr<T = String> {
fn who(&self, ctx: &TldrContext) -> TldrResult<T>;
fn what(&self, ctx: &TldrContext) -> TldrResult<T>;
fn when(&self, ctx: &TldrContext) -> TldrResult<T>;
fn where(&self, ctx: &TldrContext) -> TldrResult<T>;
fn why(&self, ctx: &TldrContext) -> TldrResult<T>;
fn whence(&self, ctx: &TldrContext) -> TldrResult<T>;
fn how(&self, ctx: &TldrContext) -> TldrResult<T>;
}
TldrContextpub struct TldrContext {
pub language: TldrLanguage,
}
TldrLanguagepub enum TldrLanguage {
#[default]
English,
// ...
Other(String),
}
TldrResultpub type TldrResult<T = String, E = Box<dyn Error>> =
Result<Option<T>, E>;
TldrSummarypub struct TldrSummary<T = String> {
pub who: Option<T>,
pub what: Option<T>,
pub when: Option<T>,
pub where: Option<T>,
pub why: Option<T>,
pub whence: Option<T>,
pub how: Option<T>,
}
ToTldrpub trait ToTldr<T = String> {
fn to_tldr(&self) -> Box<dyn Tldr<T>>;
}
git clone https://github.com/dryrust/tldr.rs.git