rust

std::ops::Add or core::ops::Add?

微笑、不失礼 提交于 2020-06-23 05:44:12
问题 These two traits (std::ops::Add, core::ops::Add) provide the same functionality, and they both use the same example (both utilize std::ops::Add ). Their set of implementors differ somewhat. Should one default to using std::ops::Add ? Why do both, as opposed to one, of them exist? 回答1: There aren't two traits. There is one trait which is exported under several interchangeable names. This is far from unique . Virtually everything in core is also exported from std , and virtually always under

std::ops::Add or core::ops::Add?

限于喜欢 提交于 2020-06-23 05:44:07
问题 These two traits (std::ops::Add, core::ops::Add) provide the same functionality, and they both use the same example (both utilize std::ops::Add ). Their set of implementors differ somewhat. Should one default to using std::ops::Add ? Why do both, as opposed to one, of them exist? 回答1: There aren't two traits. There is one trait which is exported under several interchangeable names. This is far from unique . Virtually everything in core is also exported from std , and virtually always under

link.exe not found error while running on windows system for rust program, is Visual C++ mandatory for Cargo?

三世轮回 提交于 2020-06-23 04:35:20
问题 I am getting link.exe not found issue , is there anything more i have to install? PS C:\Users\parik> cargo new test2 Created binary (application) test2 project PS C:\Users\parik> cargo build error: could not find Cargo.toml in C:\Users\parik or any parent directory PS C:\Users\parik> cd test2 PS C:\Users\parik\test2> cargo build Compiling test2 v0.1.0 (C:\Users\parik\test2) error: linker link.exe not found | = note: The system cannot find the file specified. (os error 2) note: the msvc

Is it possible to create a wrapper around an &mut that acts like an &mut

…衆ロ難τιáo~ 提交于 2020-06-23 04:14:28
问题 The following code fails to compile because MutRef is not Copy . It can not be made copy because &'a mut i32 is not Copy. Is there any way give MutRef similar semantics to &'a mut i32 ? The motivation for this is being able to package up a large set of function parameters into a struct so that they can be passed as a group instead of needing to be passed individually. struct MutRef<'a> { v: &'a mut i32 } fn wrapper_use(s: MutRef) { } fn raw_use(s: &mut i32) { } fn raw_ref() { let mut s: i32 =

How do I go from a NaiveDate to a specific TimeZone with Chrono?

痴心易碎 提交于 2020-06-22 22:51:28
问题 I am parsing dates and times in Rust using the chrono crate. The dates and times are from a website in which the date and time are from different sections of the page. The date is shown in the format %d/%m/%Y (example: 27/08/2018). The time is shown with only the hour (example: 12, 10, 21, etc.) I want to store these datetimes as UTC so that I can compute time remaining until a given datetime from now in a "timezone agnostic" way. I know which timezone these datetimes are from (Paris time). I

Issuing a warning at compile time?

心不动则不痛 提交于 2020-06-22 21:26:21
问题 I want to issue a warning at compile time, perhaps from a macro. It should not be silenceable by cap_lints . My current use case is feature deprecation, but there's other possible uses for this. 回答1: This currently isn't possible in stable Rust. However, there is an unstable feature, procedural macro diagnostics, which provides this functionality for procedural macros, via the Diagnostic API. To emit a compiler warning from inside a procedural macro, you would use it like this: #![feature

Issuing a warning at compile time?

前提是你 提交于 2020-06-22 21:24:09
问题 I want to issue a warning at compile time, perhaps from a macro. It should not be silenceable by cap_lints . My current use case is feature deprecation, but there's other possible uses for this. 回答1: This currently isn't possible in stable Rust. However, there is an unstable feature, procedural macro diagnostics, which provides this functionality for procedural macros, via the Diagnostic API. To emit a compiler warning from inside a procedural macro, you would use it like this: #![feature

What is the rationale behind allowing variable shadowing in Rust? [closed]

纵饮孤独 提交于 2020-06-22 16:39:06
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 months ago . Improve this question In Rust it is encouraged to shadow variables: But wait, doesn’t the program already have a variable named guess? It does, but Rust allows us to shadow the previous value of guess with a new one. Won't this feature just introduce problems like: hard to

How is Rust compiled to machine code?

痞子三分冷 提交于 2020-06-22 11:05:36
问题 I've recently been looking at the Rust programming language. How does it work? Rust code seems to be compiled into ELF or PE (etc) binaries, but I've not been able to find any information on how that's done? Is it compiled to an intermediate format then compiled the rest of the way with gxx for example? Any help (or links) would be really appreciated. 回答1: The code-generation phase of the Rust compiler is mainly done by LLVM . LLVM is a set of tools for building a compiler, most notably used

How is Rust compiled to machine code?

泪湿孤枕 提交于 2020-06-22 11:04:21
问题 I've recently been looking at the Rust programming language. How does it work? Rust code seems to be compiled into ELF or PE (etc) binaries, but I've not been able to find any information on how that's done? Is it compiled to an intermediate format then compiled the rest of the way with gxx for example? Any help (or links) would be really appreciated. 回答1: The code-generation phase of the Rust compiler is mainly done by LLVM . LLVM is a set of tools for building a compiler, most notably used