mit_commit_message_lints/relates/lib/
relates_to.rs1use std::borrow::Cow;
2
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Eq, PartialEq, Serialize, Deserialize, Clone)]
7pub struct RelateTo<'a> {
8 relates: Cow<'a, str>,
9}
10
11impl<'a> RelateTo<'a> {
12 #[must_use]
14 pub const fn new(relates: Cow<'a, str>) -> Self {
15 Self { relates }
16 }
17
18 #[must_use]
20 pub fn to(&self) -> &str {
21 &self.relates
22 }
23}
24
25impl<'a> From<&'a str> for RelateTo<'a> {
26 fn from(input: &'a str) -> Self {
27 RelateTo {
28 relates: Cow::Borrowed(input),
29 }
30 }
31}
32impl From<String> for RelateTo<'_> {
33 fn from(input: String) -> Self {
34 RelateTo {
35 relates: Cow::Owned(input),
36 }
37 }
38}