出于学习目的,我尝试了这个解决方案,但它不起作用:
use std::ops::Add;
fn inc<T: Add>(x:&mut T) {
*x += 1;
}
fn main() {
let mut x:i32 = 10;
let mut y:u8 = 1;
inc(&mut x);
inc(&mut y);
println!("{} {}", x, y);
}
Run Code Online (Sandbox Code Playgroud)
错误信息:
<anon>:4:5: 4:7 error: binary assignment operation `+=` cannot be applied to types `T` and `_` [E0368]
<anon>:4 *x += 1;
^~
<anon>:4:5: 4:7 help: see the detailed explanation for E0368
error: aborting due to previous error
Run Code Online (Sandbox Code Playgroud)
这样做的正确方法是什么?
我为命令行编写了钩子:
# Transforms command 'ls?' to 'man ls'
function question_to_man() {
if [[ $2 =~ '^\w+\?$' ]]; then
man ${2[0,-2]}
fi
}
autoload -Uz add-zsh-hook
add-zsh-hook preexec question_to_man
Run Code Online (Sandbox Code Playgroud)
但当我这样做时:
> ls?
Run Code Online (Sandbox Code Playgroud)
退出后man我得到:
> zsh: no matches found: ls?
Run Code Online (Sandbox Code Playgroud)
如何摆脱有关错误命令的消息?