Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.
use super::funejson::Value; ← the fune runtime: the JSON value the test vectors use; fune build keeps it only where a signature takes one
use super::validation_email::is_email; ← from validation.email ^1.0.0 · built alongside by fune
fn is_ascii_space(ch: char) -> bool {
matches!(ch, ' ' | '\t' | '\n' | '\r' | '\u{0C}' | '\u{0B}')
}
/// The stored form of an email address: trimmed, domain lower-cased, local
/// part as typed; `None` when the trimmed text is not a plausible address.
pub fn normalise_email(value: &str) -> Option<String> {
// ASCII whitespace only; str::trim also strips Unicode spaces.
let trimmed = value.trim_matches(is_ascii_space);
if !is_email(trimmed) {
return None;
}
let at = trimmed.find('@').unwrap();
Some(format!("{}{}", &trimmed[..=at], trimmed[at + 1..].to_ascii_lowercase()))
}
pub fn fune_vector(args: &[Value]) -> Value {
match normalise_email(args[0].as_str()) {
Some(email) => Value::Str(email),
None => Value::Null,
}
}