我正在尝试简化 this Nodejs-Polars 代码。
我有
path_or_buffer: Either<String, Buffer>
作为函数参数。
尝试匹配时:
let file = match path_or_buffer {
Either::A(path) => Box::new(std::fs::File::open(path).unwrap()) as Box<dyn MmapBytesReader>,
Either::B(buffer) => Box::new(Cursor::new(buffer.as_ref())) as Box<dyn MmapBytesReader>
}
我得到:
error[E0597]: buffer does not live long enough
谢谢
这是我在GH中的解决方案。谢谢大家!