tldr-traits

Crates.iotldr-traits
lib.rstldr-traits
version0.1.1
created_at2025-08-04 11:01:54.762962+00
updated_at2025-08-06 06:55:52.596865+00
descriptionAbstractions for TL;DR summarization using the five Ws: who? what? when? where? why?
homepagehttps://github.com/dryrust/tldr.rs
repositoryhttps://github.com/dryrust/tldr.rs
max_upload_size
id1780592
size27,088
owners (github:dryrust:owners)

documentation

README

TL;DR.rs

License Compatibility Package Documentation

Rust abstractions for TL;DR summarization using the five Ws: who? what? when? where? why?

✨ Features

  • Provides the Tldr trait for generating TL;DR summaries.
  • Provides the ToTldr trait for converting objects into TL;DR summaries.
  • Supports multilingual TL;DR generation while defaulting to English.
  • Zero required dependencies, only optional integrations with Serde & Bon.
  • Adheres to the Rust API Guidelines in its naming conventions.
  • 100% free and unencumbered public domain software.

🛠️ Prerequisites

  • Rust 1.85+ (2024 edition)

⬇️ Installation

Installation via Cargo

cargo add tldr-traits --rename tldr

Installation in Cargo.toml (with all features enabled)

[dependencies]
tldr = { version = "0", package = "tldr-traits" }

Installation in Cargo.toml (with only specific features enabled)

[dependencies]
tldr = { version = "0", package = "tldr-traits", default-features = false, features = ["serde"] }

👉 Examples

Importing the Library

use tldr::{Tldr, TldrContext, TldrLanguage, TldrResult, TldrSummary, ToTldr};

Implementing the Trait

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)))
    }
}

📚 Reference

Tldr

pub 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>;
}

TldrContext

pub struct TldrContext {
    pub language: TldrLanguage,
}

TldrLanguage

pub enum TldrLanguage {
    #[default]
    English,
    // ...
    Other(String),
}

TldrResult

pub type TldrResult<T = String, E = Box<dyn Error>> =
    Result<Option<T>, E>;

TldrSummary

pub 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>,
}

ToTldr

pub trait ToTldr<T = String> {
    fn to_tldr(&self) -> Box<dyn Tldr<T>>;
}

👨‍💻 Development

git clone https://github.com/dryrust/tldr.rs.git

Share on X Share on Reddit Share on Hacker News Share on Facebook Share on LinkedIn

Commit count: 0

cargo fmt