小编jon*_*dev的帖子

go float 零除编译器错误

这种行为有何意义?仅打印编译器警告而不是错误不是更有意义吗?

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:除以零

go divide-by-zero

5
推荐指数
1
解决办法
3762
查看次数

rust clap 解析 ipv4Addr

我想使用 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)

rust clap

5
推荐指数
1
解决办法
1398
查看次数

标签 统计

clap ×1

divide-by-zero ×1

go ×1

rust ×1