just_string/traits_a.rs
1use std::{borrow::Cow, ops::Add};
2
3use crate::JustString;
4
5impl<'x> Add<&'x str> for JustString<'x> {
6 type Output = Self;
7
8 fn add(self, rhs: &'x str) -> Self::Output {
9 match self {
10 Self::RefStr(s) => Self::CowStr(Cow::Borrowed(s) + rhs),
11 Self::RefString(s) => Self::String(s.clone() + rhs),
12 Self::CowStr(s) => Self::CowStr(s + rhs),
13 Self::String(s) => Self::String(s + rhs),
14 Self::BoxStr(s) => Self::BoxStr((s.to_string() + rhs).into_boxed_str()),
15 }
16 }
17}