mirror of
https://github.com/YGGverse/ggemtext.git
synced 2026-03-31 09:05:32 +00:00
26 lines
698 B
Rust
26 lines
698 B
Rust
use super::TAG;
|
|
|
|
pub trait Gemtext {
|
|
/// Get [Gemtext](https://geminiprotocol.net/docs/gemtext-specification.gmi) value for `Self`
|
|
fn as_value(&self) -> Option<&str>;
|
|
/// Convert `Self` to [Gemtext](https://geminiprotocol.net/docs/gemtext-specification.gmi) line
|
|
fn to_source(&self) -> String;
|
|
}
|
|
|
|
impl Gemtext for str {
|
|
fn as_value(&self) -> Option<&str> {
|
|
self.strip_prefix(TAG).map(|s| s.trim())
|
|
}
|
|
fn to_source(&self) -> String {
|
|
format!("{TAG} {}", self.trim())
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn test() {
|
|
const SOURCE: &str = "* Item";
|
|
const VALUE: &str = "Item";
|
|
|
|
assert_eq!(SOURCE.as_value(), Some(VALUE));
|
|
assert_eq!(VALUE.to_source(), SOURCE)
|
|
}
|