Skip to main content

non_empty_str/
cmp.rs

1use core::ops::Deref;
2
3use crate::{
4    internals::{partial, total},
5    str::NonEmptyStr,
6};
7
8// NonEmptyStr
9
10total!(NonEmptyStr => as_str);
11
12partial!(NonEmptyStr => as_str, str);
13partial!(NonEmptyStr, &str => deref);
14
15partial!(NonEmptyStr, &NonEmptyStr => deref);
16
17#[cfg(any(feature = "std", feature = "alloc"))]
18mod std_or_alloc {
19    cfg_select! {
20        feature = "std" => {
21            use std::borrow::Cow;
22        }
23        feature = "alloc" => {
24            use alloc::{borrow::Cow, boxed::Box, string::String};
25        }
26        _ => {
27            compile_error!("expected either `std` or `alloc` to be enabled");
28        }
29    }
30
31    use core::ops::Deref;
32
33    use crate::{
34        boxed::NonEmptyBoxedStr,
35        cow::NonEmptyCowStr,
36        internals::{partial, total},
37        str::NonEmptyStr,
38        string::NonEmptyString,
39    };
40
41    // NonEmptyStr (continued)
42
43    partial!(NonEmptyStr, Box<str> => as_ref);
44    partial!(NonEmptyStr, Cow<'_, str> => as_ref);
45    partial!(NonEmptyStr, String => as_str);
46
47    partial!(NonEmptyStr, NonEmptyCowStr<'_> => as_ref);
48
49    // NonEmptyString
50
51    total!(NonEmptyString => as_string);
52
53    partial!(NonEmptyString => as_string, String);
54    partial!(NonEmptyString => as_non_empty_str, NonEmptyStr);
55    partial!(NonEmptyString, &NonEmptyStr => deref);
56    partial!(NonEmptyString => as_str, str);
57    partial!(NonEmptyString, &str => deref);
58    partial!(NonEmptyString, NonEmptyCowStr<'_> => as_ref);
59    partial!(NonEmptyString, Cow<'_, str> => as_ref);
60    partial!(NonEmptyString, NonEmptyBoxedStr => as_ref);
61    partial!(NonEmptyString, Box<str> => as_ref);
62
63    // NonEmptyBoxedStr
64
65    partial!(NonEmptyBoxedStr => as_ref, NonEmptyStr);
66    partial!(NonEmptyBoxedStr, &NonEmptyStr => deref);
67    partial!(NonEmptyBoxedStr => as_ref, str);
68    partial!(NonEmptyBoxedStr, &str => deref);
69    partial!(NonEmptyBoxedStr => as_ref, Box<str>);
70    partial!(NonEmptyBoxedStr, NonEmptyCowStr<'_> => as_ref);
71    partial!(NonEmptyBoxedStr, Cow<'_, str> => as_ref);
72    partial!(NonEmptyBoxedStr => as_ref, String);
73}