类似这种:
struct A;
struct B;
let a = get_vec(A);
let b = get_vec(B);
fn get_vec<T>(T) -> Vec<T> {
  let s: Vec<T> = Vec::new();
  // Do something
  // s.push(something)
  s
}
Vec<> 这里是需要具体的 struct
已解决,感谢各位回答,感谢 whfuyn 大佬的方法:
struct A;
struct B;
fn main() {
    let a: Vec<A> = get_vec::<A>();
    let b: Vec<B> = get_vec::<B>();
}
fn get_vec<T>() -> Vec<T> {
  let s: Vec<T> = Vec::new();
  // Do something
  // s.push(something)
  s
}
	    
	    
		1
	    
	    
	    共 3 条评论, 1 页
	
	
    
评论区
写评论Playgroud
用宏实现;