1use std::borrow::Cow;
2
3#[derive(Default, Debug, Clone)]
5pub struct Upstream<'a>(pub Cow<'a, [u8]>);
6
7impl<'a> Upstream<'a> {
8 pub const EMPTY: Upstream<'static> = Upstream(Cow::Borrowed(&[]));
9}
10
11impl<'a> From<String> for Upstream<'a> {
12 fn from(value: String) -> Self {
13 Self(Cow::Owned(value.into_bytes()))
14 }
15}
16
17impl<'a> From<Vec<u8>> for Upstream<'a> {
18 fn from(value: Vec<u8>) -> Self {
19 Self(Cow::Owned(value))
20 }
21}
22
23impl<'a, T: AsRef<[u8]>> From<&'a T> for Upstream<'a> {
24 fn from(value: &'a T) -> Self {
25 Self(Cow::Borrowed(value.as_ref()))
26 }
27}