cw_storage_plus/
namespace.rs1use std::borrow::Cow;
2
3#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
9pub struct Namespace(Cow<'static, [u8]>);
10
11impl Namespace {
12 pub const fn from_static_str(s: &'static str) -> Namespace {
13 Namespace(Cow::Borrowed(s.as_bytes()))
14 }
15
16 pub fn as_slice(&self) -> &[u8] {
17 self.0.as_ref()
18 }
19}
20
21impl From<&'static str> for Namespace {
22 fn from(s: &'static str) -> Self {
23 Namespace(Cow::Borrowed(s.as_bytes()))
24 }
25}
26
27impl From<String> for Namespace {
28 fn from(s: String) -> Self {
29 Namespace(Cow::Owned(s.into_bytes()))
30 }
31}
32
33impl From<Cow<'static, [u8]>> for Namespace {
34 fn from(s: Cow<'static, [u8]>) -> Self {
35 Namespace(s)
36 }
37}