commented/
lib.rs

1//! [![crates.io](https://img.shields.io/crates/v/commented?style=flat-square&logo=rust)](https://crates.io/crates/commented)
2//! [![docs.rs](https://img.shields.io/badge/docs.rs-commented-blue?style=flat-square&logo=docs.rs)](https://docs.rs/commented)
3//! ![license](https://img.shields.io/badge/license-Apache--2.0_OR_MIT-blue?style=flat-square)
4//! ![msrv](https://img.shields.io/badge/msrv-1.85-blue?style=flat-square&logo=rust)
5//! [![github](https://img.shields.io/github/stars/nik-rev/commented)](https://github.com/nik-rev/commented)
6//!
7//! This crate contains the [`comment`](comment) function, which turns the passed input
8//! into a comment for the given file type
9//!
10//! ```toml
11//! commented = "0.2.0"
12//! ```
13//!
14//! # Usage
15//!
16//! ```rust
17//! use commented::comment;
18//!
19//! assert_eq!(comment("hello, world!", "index.html"), "<!-- hello, world! -->");
20//! assert_eq!(comment("hello, world!", "main.rs"), "/* hello, world! */");
21//! assert_eq!(comment("hello, world!", "script.lua"), "--[[ hello, world! --]]");
22//! // fallback to `#`, as that's the most common comment tokens for
23//! // files without an extension
24//! assert_eq!(comment("hello, world!", "123456789"), "# hello, world!");
25//! ```
26
27use std::path::Path;
28
29mod generated;
30
31/// Turn the given `content` into a comment for the given `path`
32///
33/// # Examples
34///
35/// ```
36/// use commented::comment;
37///
38/// assert_eq!(comment("hello, world!", "index.html"), "<!-- hello, world! -->");
39/// assert_eq!(comment("hello, world!", "main.rs"), "/* hello, world! */");
40/// assert_eq!(comment("hello, world!", "script.lua"), "--[[ hello, world! --]]");
41/// // fallback to `#`, as that's the most common comment tokens for
42/// // files without an extension
43/// assert_eq!(comment("hello, world!", "123456789"), "# hello, world!");
44/// ```
45pub fn comment<S: ToString, P: AsRef<Path>>(content: S, path: P) -> String {
46    generated::comment(content, path)
47}