babyrite/expand.rs
1//! Link expansion module.
2//!
3//! This module provides common types for expanding various types of links
4//! (Discord message links, GitHub permalinks, etc.) into rich preview content.
5
6pub mod discord;
7pub mod github;
8
9use serenity_builder::model::embed::SerenityEmbed;
10
11/// Expanded content produced by a link expander.
12///
13/// Represents the different kinds of content that can result from
14/// expanding a link.
15pub enum ExpandedContent {
16 /// A Discord message preview displayed as an embed.
17 Embed(Box<SerenityEmbed>),
18 /// A code block with syntax highlighting (e.g. GitHub permalink).
19 CodeBlock {
20 /// The programming language for syntax highlighting.
21 language: String,
22 /// The code content.
23 code: String,
24 /// Metadata line displayed above the code block (e.g. file path, line range).
25 metadata: String,
26 },
27}
28
29/// Errors that can occur during link expansion.
30#[derive(thiserror::Error, Debug)]
31pub enum ExpandError {
32 /// An error from the Discord message link expander.
33 #[error(transparent)]
34 Discord(#[from] discord::PreviewError),
35 /// An error from the GitHub permalink expander.
36 #[error(transparent)]
37 GitHub(#[from] github::GitHubExpandError),
38}