我正在写一个新的箱子.我为它编写了一些测试并运行测试cargo test.之后,在target文件夹中生成一些test_xxx可执行文件.我启用了调试选项Cargo.toml.通过运行gdb targets/test_xxx,我可以列出并调试test_xxx文件中的代码.但是,我无法进入箱子里的功能.没有调试信息.如何构建/链接包以包含其调试信息?
跟进
我做了更多的研究,发现我的原始问题是不准确的.它不会发生在外部包中的所有方法中,而只会发生在那些通用方法中.我提交了一个详细步骤的问题:https://github.com/rust-lang/rust/issues/19228.请在那里阅读评论.
这是我正在做的调试泛型方法:
gdb调试lib.在像C#这样的语言中,给出这个代码(我没有await故意使用关键字):
async Task Foo()
{
var task = LongRunningOperationAsync();
// Some other non-related operation
AnotherOperation();
result = task.Result;
}
Run Code Online (Sandbox Code Playgroud)
在第一行中,long操作在另一个线程中运行,并Task返回a(即未来).然后,您可以执行另一个与第一个并行运行的操作,最后,您可以等待操作完成.我认为,这也是行为async/ await在Python,JavaScript等
另一方面,在Rust中,我在RFC中读到:
Rust的期货与其他语言的期货之间的根本区别在于,除非进行调查,否则Rust的期货不会做任何事情.整个系统是围绕这个建立的:例如,取消正在降低未来正是出于这个原因.相比之下,在其他语言中,调用异步fn会旋转一个立即开始执行的未来.
在这种情况下,是什么目的async/ await鲁斯特?看到其他语言,这种表示法是一种运行并行操作的便捷方式,但是如果调用async函数没有运行任何东西,我无法看到它在Rust中是如何工作的.
我应该使用什么类型的向量来存储 future?
我尝试在同一个 URL 上发出多个并发请求,并将所有 future 保存到向量中以与join_all.
如果我没有明确设置向量的类型,则一切正常。我知道 Rust 可以找到变量的正确类型。CLion 确定向量类型为Vec<dyn Future<Output = ()>>,但是当我尝试自己设置类型时,它给了我一个错误:
error[E0277]: the size for values of type `dyn core::future::future::Future<Output = ()>` cannot be known at compilation time
--> src/lib.rs:15:23
|
15 | let mut requests: Vec<dyn Future<Output = ()>> = Vec::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `dyn core::future::future::Future<Output = ()>`
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
= …Run Code Online (Sandbox Code Playgroud) 背景:在Rust中,通常会调用多个源文件mod.rs.例如:
app_name
src
main.rs
foo
mod.rs
bar
mod.rs
Run Code Online (Sandbox Code Playgroud)
问题:mod.rs在设置LLDB断点时,我无法找到区分彼此的方法:
$ cargo build
$ rust-lldb target/debug/app_name
(lldb) breakpoint set -f mod.rs -l 10
Breakpoint 1: 2 locations.
(lldb) breakpoint set -f foo/mod.rs -l 10
Breakpoint 2: no locations (pending).
WARNING: Unable to resolve breakpoint to any actual locations.
(lldb) breakpoint set -f src/foo/mod.rs -l 10
Breakpoint 3: no locations (pending).
WARNING: Unable to resolve breakpoint to any actual locations.
Run Code Online (Sandbox Code Playgroud)
这个问题最常见mod.rs.更一般地说,任何时候多个源文件共享相同的名称就会出现.
问题:有没有办法在第10行foo/mod.rs而不是第10 …