我试图使用一个共享的信号量使用futures_intrusive::sync::GenericSemaphore
use std::path::Path;
use futures_intrusive::sync::GenericSemaphore;
async fn refresh_file(raster_file: &Path, slr: f64, output_path: &Path, chunk_size: u32, semaphore: &GenericSemaphore) {
if output_path.exists().not() {
build_required_windows(&raster_file, slr, chunk_size, output_path, &semaphore).await?;
}
}然而,我得到了一个错误:
error[E0107]: missing generics for struct `GenericSemaphore`
--> src/linear_bathtubbing.rs:129:106
|
129 | pub async fn refresh_file(raster_file: &Path, slr: f64, output_path: &Path, chunk_size: u32, semaphore: &GenericSemaphore) {
| ^^^^^^^^^^^^^^^^ expected 1 generic argument
|
note: struct defined here, with 1 generic parameter: `MutexType`
--> /.../.cargo/registry/src/github.com-1ecc6299db9ec823/futures-intrusive-0.4.0/src/sync/semaphore.rs:433:12
|
433 | pub struct GenericSemaphore<MutexType: RawMutex> {
| ^^^^^^^^^^^^^^^^ ---------
help: add missing generic argument
|
129 | pub async fn refresh_file(raster_file: &Path, slr: f64, output_path: &Path, chunk_size: u32, semaphore: &GenericSemaphore<MutexType>) {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~似乎我需要“添加缺少的泛型参数”,但我不知道如何继续。我尝试过指定Mutex类型和其他东西,但没有成功,但我认为这可能有一个简单的答案。
发布于 2022-06-11 20:25:08
只需将GenericSemaphore期望的泛型类型参数添加到函数签名中即可。
async fn refresh_file<T: RawMutex>(
raster_file: &Path,
slr: f64,
output_path: &Path,
chunk_size: u32,
semaphore: &GenericSemaphore<T>
) {或者,使用impl语法(对于上面的代码来说,这是糖):
async fn refresh_file(
raster_file: &Path,
slr: f64,
output_path: &Path,
chunk_size: u32,
semaphore: &GenericSemaphore<impl RawMutex>
) {https://stackoverflow.com/questions/72586756
复制相似问题