小编Pet*_*Guo的帖子

如何从数字中解析BigInt?

我正在尝试使用BigInt.我的代码是这样的:

extern crate num;
use num::bigint::BigInt;
...
println!("{}", from_str::<BigInt>("1")); //this is line 91 in the code
Run Code Online (Sandbox Code Playgroud)

在我的Cargo.toml文件中,我有以下内容:

[dependencies]
num = "0.1.30"
Run Code Online (Sandbox Code Playgroud)

我所做的似乎与本文档中的内容相符,也是本文档,也是Stack Overflow的答案.

但是我收到以下错误:

Compiling example v0.1.0 (file:///C:/src/rust/example)
src\main.rs:91:20: 91:38 error: unresolved name `from_str` [E0425]
src\main.rs:91     println!("{}", from_str::<BigInt>("1"));
Run Code Online (Sandbox Code Playgroud)

bigint rust

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

JavaScript和分号

'use strict'
[1,2,3,4].find(x => x > 1)
Run Code Online (Sandbox Code Playgroud)

使用nodejs 5.0.0执行上述代码时,会出现以下错误:

TypeError: "use strict"[(((1 , 2) , 3) , 4)].find is not a function
at Object.<anonymous> (C:\src\nodejs\ecma6.js:2:11)
at Module._compile (module.js:425:26)
at Object.Module._extensions..js (module.js:432:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Function.Module.runMain (module.js:457:10)
at startup (node.js:136:18)
at node.js:972:3
Run Code Online (Sandbox Code Playgroud)

如果我在'use strict'之后添加分号,则错误消失.

这看起来像一个错误......或者是否有更深层次的含义 - 意味着语言规范中是否存在一个特殊情况列表,其中需要使用分号.

更新

语言规范列出了特殊情况,其中需要显式分号.

strict typeerror node.js

4
推荐指数
1
解决办法
2377
查看次数

MySQL:使用列表中的随机数更新所有行

我需要运行一个SQL查询,从列表中选择一个随机数并用它更新一个特定的列.

数字列表:

(101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122)

兰德表:(结构)

id  rand    type
1    0       false
2    0       true
3    0       false
4    0       true
5    0       true
Run Code Online (Sandbox Code Playgroud)

我需要从列表中选择随机数并更新"rand"列,

mysql sql

3
推荐指数
2
解决办法
3087
查看次数

为什么我需要声明"extern crate core"才能使用libcore?

随着核心库拉斯特1.6稳定,以下成为可能,并且我也不需要更换libcorelibstd任何更多:

//extern crate core; //won't work without this line
extern crate num;

use core::ops::Add;
use num::bigint::{BigInt};

fn main() {
    let mut big = "8705702225074732811211966512111".parse::<BigInt>().unwrap();
    let one = "1".parse::<BigInt>().unwrap();
    big = big.add(&one);
    println!("{:?}", big);
}
Run Code Online (Sandbox Code Playgroud)

但是有一件事让我感到困惑 - 为什么我需要宣布"extern crate core;"?据我所知,libstd意在构建之上libcore.libcore意味着独立于操作系统,而实现libstd可以是特定于操作系统的.我从来没有必要指定"extern crate std".令我困惑的是,libcore在上述情况下,我不需要在Cargo.toml中添加依赖项,尽管它是一个外部箱子.

libcore唯一的此类情况?当语言的实现变得稳定时,这是暂时的吗?

rust rust-cargo

3
推荐指数
1
解决办法
1207
查看次数

标签 统计

rust ×2

bigint ×1

mysql ×1

node.js ×1

rust-cargo ×1

sql ×1

strict ×1

typeerror ×1