我有一个函数,它AsRef<Path>作为一个参数,看起来像这样
fn test<P: AsRef<std::path::Path>>(path: P) {
path.join("13123123");
}
Run Code Online (Sandbox Code Playgroud)
当我编译它时,它给了我以下错误
fn test<P: AsRef<std::path::Path>>(path: P) {
path.join("13123123");
}
Run Code Online (Sandbox Code Playgroud) 我有一个Test我想实现的结构体std::future::Future,它会轮询function:
use std::{
future::Future,
pin::Pin,
task::{Context, Poll},
};
struct Test;
impl Test {
async fn function(&mut self) {}
}
impl Future for Test {
type Output = ();
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
match self.function() {
Poll::Pending => Poll::Pending,
Poll::Ready(_) => Poll::Ready(()),
}
}
}
Run Code Online (Sandbox Code Playgroud)
那没有用:
error[E0308]: mismatched types
--> src/lib.rs:17:13
|
10 | async fn function(&mut self) {}
| - the `Output` of this `async fn`'s expected opaque …Run Code Online (Sandbox Code Playgroud) 这有效,但test_macro只接受一个参数:
macro_rules! test_define (
($name:ident) => (
macro_rules! $name (
( $x:expr ) => (
// something
)
);
)
);
test_define!(test_macro);
Run Code Online (Sandbox Code Playgroud)
如果我尝试这样做:
macro_rules! test_define2 (
($name:ident) => (
macro_rules! $name (
( $($x:expr),* ) => (
// something
)
);
)
);
test_define2!(test_macro2);
Run Code Online (Sandbox Code Playgroud)
编译失败:
error: attempted to repeat an expression containing no syntax variables matched as repeating at this depth
--> src/main.rs:4:16
|
4 | ( $($x:expr),* ) => (
| ^^^^^^^^^
Run Code Online (Sandbox Code Playgroud)