fn convert_index_aux()

in starlark/src/values/index.rs [21:53]


fn convert_index_aux(
    len: i32,
    v1: Option<Value>,
    default: i32,
    min: i32,
    max: i32,
) -> anyhow::Result<i32> {
    if let Some(v) = v1 {
        if v.is_none() {
            Ok(default)
        } else {
            match v.to_int() {
                Ok(x) => {
                    let i = if x < 0 { len + x } else { x };
                    if i < min {
                        Ok(min)
                    } else if i > max {
                        Ok(max)
                    } else {
                        Ok(i)
                    }
                }
                Err(..) => Err(ValueError::IncorrectParameterTypeWithExpected(
                    "none or int".to_owned(),
                    v.get_type().to_owned(),
                )
                .into()),
            }
        }
    } else {
        Ok(default)
    }
}