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