Skip to main content

param_type_matches

Function param_type_matches 

Source
pub fn param_type_matches(
    expected: &DataType,
    received: &DataType,
    generics: &Generics,
) -> bool
Expand description

Whether an argument of type received satisfies a parameter declared as expected.

Unknown is the any slot and the type of a value the checker cannot pin down (a json::parse result, for instance). It stands in for every type on either side, so annotating a parameter any keeps the parameter dynamic and passing a dynamic value to a typed parameter is still allowed. Every other pair uses the ordinary type equality.

The same rule reaches inside an instantiation: a constructor names only the parameters its payload mentions, so Ok(2) is a Result<int, any> and None is an Option<any>. Two instantiations of one declaration line up when every pair of arguments does, which is what lets those values be passed and returned where a fully named instantiation is expected.