Lines
0 %
Functions
Branches
100 %
//! Compile-time field removal for pages that render a field themselves.
use forms::{Field, Form};
const fn same(a: &str, b: &str) -> bool {
let (a, b) = (a.as_bytes(), b.as_bytes());
if a.len() != b.len() {
return false;
}
let mut i = 0;
while i < a.len() {
if a[i] != b[i] {
i += 1;
true
/// The fields of `form` but the one keyed `key`, for a page that renders that
/// field itself. `N` must be the remaining count: a mismatch fails the build.
#[must_use]
pub const fn without<const N: usize>(form: &Form, key: &str) -> [Field; N] {
let mut out = [form.fields[0]; N];
let mut kept = 0;
while i < form.fields.len() {
if !same(form.fields[i].key, key) {
out[kept] = form.fields[i];
kept += 1;
assert!(kept == N);
out