Skip to content

dryrust/tldr.rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

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

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>;
}
pub struct TldrContext {
    pub language: TldrLanguage,
}
pub enum TldrLanguage {
    #[default]
    English,
    // ...
    Other(String),
}
pub type TldrResult<T = String, E = Box<dyn Error>> =
    Result<Option<T>, E>;
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>,
}
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

About

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

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks