Skip to content

Opt<T> does not respect passing undefined explicitly #49

@Arshia001

Description

@Arshia001

Since Opt<T> only checks for the absence of an argument, it does not respect passing undefined explicitly. This is probably the correct implementation:

impl<'cx, T: FromValue<'cx>> FromArgument<'_, 'cx> for Opt<T> {
	type Config = T::Config;

	fn from_argument(accessor: &mut Accessor<'_, 'cx>, config: Self::Config) -> Result<Opt<T>> {
		if accessor.is_empty() {
			Ok(Opt(None))
		} else {
			let val = accessor.value();
			if val.handle().is_undefined() {
				Ok(Opt(None))
			} else {
				T::from_value(accessor.cx(), &val, false, config).map(Some).map(Opt)
			}
		}
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions