rust

Web3极客日报 #11

放肆的年华 提交于 2021-01-30 15:40:01
另一个高性能区块链开发框架 —— Muta https://github.com/nervosnetwork/muta-docs/blob/master/docs/zh/overview.md @Shooter: Muta 是一个由 Rust 编写的具备可扩展性的高性能区块链框架。它允许你使用 Rust 或 Typescript 编写你的业务逻辑,构建你的专有区块链。 同时,Muta 还是 Nervos layer2 解决方案 Axon 的底层基础设施,Muta 将内置一套跨链方案联通整个 Nervos 网络。 2.为什么选择Rust? https://mp.weixin.qq.com/s/7WiVf5B50t3vfhz504sdXg @Harry : 作者Dmitriy从内存安全,性能,测试的难易分析了Rust的优点,另外从Parity自身的角度阐述了为什么选择Rust。 3.推荐区块链学习平台——Cryptozombies https://cryptozombies.io/ @River Learn to Code Blockchain DApps By Building Simple Games CryptoZombies是一个互动学习平台,教你所有关于区块链的技术。通过完成游戏,学习智能合约。 本文由博客一文多发平台 OpenWrite 发布!

Multiple return types from a method

亡梦爱人 提交于 2021-01-30 09:11:04
问题 I am trying to write a simple TV-episode file renamer in Rust. A filename is parsed, and might be one of several types (date-based, season/episode-number based etc). This parsed file is then turned into a "populated file" with data from a database (which is then formatted into a new filename) Initially I tried having the parse method take a filename and return an enum variant: enum ParsedFile{ DateBased{series: String, date: Date}, SeasonBased{series: String, season: i32, episode: i32}, //

Multiple return types from a method

夙愿已清 提交于 2021-01-30 09:09:34
问题 I am trying to write a simple TV-episode file renamer in Rust. A filename is parsed, and might be one of several types (date-based, season/episode-number based etc). This parsed file is then turned into a "populated file" with data from a database (which is then formatted into a new filename) Initially I tried having the parse method take a filename and return an enum variant: enum ParsedFile{ DateBased{series: String, date: Date}, SeasonBased{series: String, season: i32, episode: i32}, //

Multiple return types from a method

无人久伴 提交于 2021-01-30 09:09:28
问题 I am trying to write a simple TV-episode file renamer in Rust. A filename is parsed, and might be one of several types (date-based, season/episode-number based etc). This parsed file is then turned into a "populated file" with data from a database (which is then formatted into a new filename) Initially I tried having the parse method take a filename and return an enum variant: enum ParsedFile{ DateBased{series: String, date: Date}, SeasonBased{series: String, season: i32, episode: i32}, //

Multiple return types from a method

允我心安 提交于 2021-01-30 09:08:34
问题 I am trying to write a simple TV-episode file renamer in Rust. A filename is parsed, and might be one of several types (date-based, season/episode-number based etc). This parsed file is then turned into a "populated file" with data from a database (which is then formatted into a new filename) Initially I tried having the parse method take a filename and return an enum variant: enum ParsedFile{ DateBased{series: String, date: Date}, SeasonBased{series: String, season: i32, episode: i32}, //

Multiple return types from a method

自作多情 提交于 2021-01-30 09:07:00
问题 I am trying to write a simple TV-episode file renamer in Rust. A filename is parsed, and might be one of several types (date-based, season/episode-number based etc). This parsed file is then turned into a "populated file" with data from a database (which is then formatted into a new filename) Initially I tried having the parse method take a filename and return an enum variant: enum ParsedFile{ DateBased{series: String, date: Date}, SeasonBased{series: String, season: i32, episode: i32}, //

Passing symbol values to the Rust compiler during build

青春壹個敷衍的年華 提交于 2021-01-29 21:39:53
问题 In my Go builds, I usually include these lines: buildInfo="`date -u '+%Y-%m-%dT%TZ'`|`git describe --always --long`|`git tag | tail -1`" go build -ldflags "-X main.buildInfo=${buildInfo} -s -w" ./cmd/... and then in main , I parse buildInfo into three separate values which can be displayed with the usage message. This allows me to see the compile timestamp, git hash, and semver number of the executable. Is there any similar way to do this in the Rust compiler? 回答1: You want to use a Build

How do I parse a float from a string that might contain left-over characters without doing manual parsing?

佐手、 提交于 2021-01-29 21:17:34
问题 How do I parse a float from a string that may contain left-over characters, and figure out where it ends, without doing manual parsing (e.g. parseFloat() in JS)? An example would be the string "2e-1!" . I want to evaluate the next float from the string such that I can split this string into "2e-1" and "!" (for example, if I wanted to implement a calculator.) How would I do this without writing a parser to see where the float ends, taking that as an &str , and then using .parse() ? I am aware

The proper ownership for “caching proxy” in Rust?

瘦欲@ 提交于 2021-01-29 20:00:58
问题 I'd like to use Factory to build an object from the String and have multiple impls: 1) actual building and 2) caching (stores in-memory in HashMap ). The problem is that in case #1 it have to pass the ownership and in case #2 HashMap owns the value and a reference can be returned only. use std::collections::HashMap; // product interface pub trait TProduct { fn get_title(&self) -> &String; } // and concrete impls pub struct ConcreteProduct1 { } impl TProduct for ConcreteProduct1 { // ... } pub

Passing symbol values to the Rust compiler during build

好久不见. 提交于 2021-01-29 19:52:03
问题 In my Go builds, I usually include these lines: buildInfo="`date -u '+%Y-%m-%dT%TZ'`|`git describe --always --long`|`git tag | tail -1`" go build -ldflags "-X main.buildInfo=${buildInfo} -s -w" ./cmd/... and then in main , I parse buildInfo into three separate values which can be displayed with the usage message. This allows me to see the compile timestamp, git hash, and semver number of the executable. Is there any similar way to do this in the Rust compiler? 回答1: You want to use a Build