我正在尝试使用 Aggregates.project 对文档中的数组进行切片。我的文件就像
{
"date":"",
"stype_0":[1,2,3,4]
}
Run Code Online (Sandbox Code Playgroud)
我的java代码是:
Aggregates.project(Projections.fields(
Projections.slice("stype_0", pst-1, pen-pst),Projections.slice("stype_1", pst-1, pen-pst),
Projections.slice("stype_2", pst-1, pen-pst),Projections.slice("stype_3", pst-1, pen-pst))))
Run Code Online (Sandbox Code Playgroud)
最后我得到了错误
First argument to $slice must be an array, but is of type: int
Run Code Online (Sandbox Code Playgroud)
我想这是因为 stype_0 中的第一个元素是 int ,但我真的不知道为什么?多谢!
我想在 struct A 中初始化数组,但数组的长度是一个 const 泛型。虽然我可以确保长度总是小于 32,但似乎当前的编译器不支持这一点。此外,我尝试了#![feature(const_evaluatable_checked)],它有效,但此功能已从最新的编译器中删除。你有什么想法?
#![feature(const_generics)]
struct B<E>
where
E: Copy + Default,
{
f: E,
}
struct A<E, const ITEM_NUM: usize>
where
E: Copy + Default,
{
array: [Option<Box<B<E>>>; ITEM_NUM],
}
impl<E, const ITEM_NUM: usize> A<E, ITEM_NUM>
where
E: Copy + Default,
{
fn new() -> Self {
Self {
array: Default::default(),
}
}
}
fn main() {
let aa = A::<i32, 12>::new();
}
Run Code Online (Sandbox Code Playgroud)
PS 我不知道我是否可以使用泛型数组,因为 B 结构也需要 E 泛型。