commented/lib.rs
1//! [](https://crates.io/crates/commented)
2//! [](https://docs.rs/commented)
3//! 
4//! 
5//! [](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}