1use const_macros::const_early;
4
5#[cfg(feature = "diagnostics")]
6use miette::Diagnostic;
7
8use thiserror::Error;
9
10pub const EMPTY: &str = "the string is empty";
12
13#[derive(Debug, Error)]
15#[error("the string is empty")]
16#[cfg_attr(
17 feature = "diagnostics",
18 derive(Diagnostic),
19 diagnostic(code(non_empty_str::empty), help("make sure the string is non-empty"))
20)]
21pub struct Empty;
22
23pub const fn check_str(string: &str) -> Result<(), Empty> {
29 const_early!(string.is_empty() => Empty);
30
31 Ok(())
32}
33
34pub fn check<S: AsRef<str>>(string: S) -> Result<(), Empty> {
40 check_str(string.as_ref())
41}