Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(util): add markdown format functions to util #2314

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion twilight-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ time = { default-features = false, features = ["formatting"], version = "0.3" }

[features]
builder = ["dep:twilight-model", "dep:twilight-validate"]
format = []
link = ["dep:twilight-model"]
permission-calculator = ["dep:twilight-model"]
snowflake = ["dep:twilight-model"]
full = ["builder", "link", "permission-calculator", "snowflake"]
full = ["builder", "format", "link", "permission-calculator", "snowflake"]

[package.metadata.docs.rs]
all-features = true
Expand Down
39 changes: 39 additions & 0 deletions twilight-util/src/format.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
pub trait Format {
fn bold(self) -> Self;

fn inline_code(self) -> Self;

fn italic(self) -> Self;

fn relative_timestamp(self) -> Self;

fn underline(self) -> Self;

fn strikethrough(self) -> Self;
}
HTGAzureX1212 marked this conversation as resolved.
Show resolved Hide resolved

impl Format for &str {
fn bold(self) -> Self {
concat!("**", self, "**")
}

fn inline_code(self) -> Self {
concat!("`", self, "`")
}

fn italic(self) -> Self {
concat!("*", self, "*")
}

fn relative_timestamp(self) -> Self {
concat!("<t:", self, ":R>")
}

fn underline(self) -> Self {
concat!("__", self, "__")
}

fn strikethrough(self) -> Self {
concat!("~~", self, "~~")
}
}
3 changes: 3 additions & 0 deletions twilight-util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#[cfg(feature = "builder")]
pub mod builder;

#[cfg(feature = "format")]
pub mod format;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub mod format;
pub mod fmt;


#[cfg(feature = "link")]
pub mod link;

Expand Down
Loading