这种行为有何意义?仅打印编译器警告而不是错误不是更有意义吗?
func main() {
var y float64 = 0.0
var x float64 = 4.0 / y
fmt.Println(x)
}
Run Code Online (Sandbox Code Playgroud)
+信息
func main() {
var x float64 = 4.0 / 0.0
fmt.Println(x)
}
Run Code Online (Sandbox Code Playgroud)
prog.go:9:22:除以零
我想使用 clap 派生 API 来解析Ipv4Addr.
#![allow(unused)]
use clap; // 3.1.6
use clap::Parser;
use std::net::Ipv4Addr;
#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
struct Args {
#[clap(short, long, parse(from_str))]
ip_dst: Ipv4Addr,
}
fn main() {
let args = Args::parse();
}
Run Code Online (Sandbox Code Playgroud)
我的尝试给出了以下错误,即使 Ipv4Addr 似乎实现了FromStr它提供的from_str
error[E0277]: the trait bound `Ipv4Addr: From<&str>` is not satisfied
--> src/main.rs:10:31
|
10 | #[clap(short, long, parse(from_str))]
| ^^^^^^^^ the trait `From<&str>` is not implemented for `Ipv4Addr`
|
= help: the following implementations …Run Code Online (Sandbox Code Playgroud)