I am looking to use the polars
crate for Rust but with custom datatypes that are effectively transparent new-type wrappers around supported primitives.
Here is a simple example of what I’m trying to achieve, but doesn’t work (rustc-stable v1.79.0, polars v0.41.3):
use polars::prelude::*;
#[repr(transparent)]
struct NewType(f64);
fn main() {
let value1 = NewType(4.77);
let value2 = NewType(-6.1);
// doesn't work because `NewType` is unknown by Polars.
let ser = Series::new("a", &[value1, value2]);
println!("{ser}");
}
The compiler error is trait polars::prelude::NamedFrom<&[NewType; 2], _>
is not implemented for polars::prelude::Series
.
This makes sense, but I can’t implement NamedFrom
for Series
because of Rust’s orphan rules.
Are there any other options for using new-type datatypes in polars-rust?