Skip to main content

classify_choice_param

Function classify_choice_param 

Source
pub(crate) fn classify_choice_param(
    attrs: &mut ParamAttrs,
    param_name: &str,
    ty: &Type,
    has_default: bool,
) -> Result<()>
Expand description

Record the layers of a match_arg / choices parameter’s type on its ParamAttrs (optional, omittable, either_noun) and reject the shapes the codegen cannot serve, now that the type is known. Shared by the standalone-fn parser and finalize_method_param_attrs so the two cannot classify a type differently. A no-op for other parameters.

Accepted, outermost layer first: an optional Missing<..> (#1551), an optional Option<..> (#1473), an optional Either<.., R>, then the scalar choice type (so T, Option<T>, Missing<Option<T>>, Either<T, R>, Option<Either<T, R>>, …). A several_ok parameter takes any container (Vec<T>, Box<[T]>, &[T], [T; N]) bare, and only the owned Vec<T> / Box<[T]> under a layer: Missing<Vec<T>>, Either<Vec<T>, R> (#1612) and the Missing / Option stacks over that Either, which follow the scalar Either rule. A bare Option<Vec<T>> stays rejected: its NULL already means every choice, while under Either it goes to R. has_default says whether the parameter carries a default, which a choice with a NULL formal (Option<..> without Missing) cannot, nor one under Missing<..> (missing_choice_default_msg).