extendr icon indicating copy to clipboard operation
extendr copied to clipboard

Consider panic if not type function or macro

Open JosiahParry opened this issue 1 year ago • 3 comments

I am finding myself doing type checking inside of rust functions that accept a vctrs_vctr which is a list of pointers to struct impls. I cannot create a vector of pointers without the List Altrep https://github.com/extendr/extendr/issues/503 so the type checking from rust only checks for List.

To check that the vector class is correct i write something along the lines of

fn check_class(x: List) {
   if !x.inherits("my_vctrs_vctr") {
     panic!("`x` must be of class `"my_vctrs_vctr"`)
   }
}

A helper function / macro would be very useful here.

JosiahParry avatar Jul 14 '23 16:07 JosiahParry