问题标签 [rust]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
17583 浏览

oop - Rust 中的对象和类

我正在摆弄 Rust,通过示例,尝试创建一个类。我一直在看的例子StatusLineText

它不断提出错误:

我的代码很简单:

0 投票
1 回答
3958 浏览

rust - How do I compile a multi-file crate in Rust?

I'm trying to figure out how to compile multi-file crates in Rust, but I keep getting a compile error.

I have the file I want to import into the crate thing.rs:

And my crate file test.rc:

When I run rust build test.rc I get:

There's obviously something simple about how modules, crates and use work that I'm just not getting. My understanding was that mod something; for files in the same directory or extern mod something; for libraries on the library path caused the object file to be linked. Then use would allow you to import parts of the module into the current file, function or module. This seems to work for stuff in the core library.

This is with version 0.6 of the rust compiler.

0 投票
2 回答
28856 浏览

tcp - 用 Rust 编写的示例 TCP 服务器

我正在寻找 Rust 中的 TCP 服务器示例。

'hello world' 或 echo 服务器都很棒。

0 投票
1 回答
12735 浏览

rust - Rust 的生命周期

有时我发现自己想编写可以通过以下两种方式之一调用的函数:

我的第一个猜测是对参数类型使用借用的指针 ( &str),但是当它不起作用时(它只允许我使用@strand ~str),我尝试了以下方法(通过复制 Rust 库),它确实有效。

问题是我不明白我在做什么。根据我所能收集到的信息(主要来自编译器错误),我声明了一个没有限制的生命周期,并使用它来描述路径参数(这意味着任何生命周期都可以作为参数传递)。

所以:

  • 我的理解模糊准确吗?
  • 什么是一生?我在哪里可以了解更多关于它们的信息?
  • &str上例中类型参数和类型参数有什么区别&'a str
  • 当我在做的时候,什么是'self

(我使用的是 Rust 0.7,如果它对答案有影响的话)

0 投票
4 回答
14582 浏览

cross-platform - Building a cross-platform application (using Rust)

I started to learn Rust programming language and I use Linux. I'd like to build a cross-platform application using this language.

The question might not be related to Rust language in particular, but nonetheless, how do I do that? I'm interested in building a "Hello World" cross-platform application as well as for more complicated ones. I just need to get the idea.

So what do I do?

UPDATE:

What I want to do is the ability to run a program on 3 different platforms without changing the sources. Do I have to build a new binary file for each platform from the sources? Just like I could do in C

0 投票
2 回答
467 浏览

functional-programming - 你如何在像 rust 这样的函数式语言中分享实现细节?

我有时会发现自己在 C# 中编写了部分实现的抽象类:

尽管这种控制结构很聪明,但我如何用像 rust 这样的函数式语言来完成这个(部分共享实现)?

0 投票
1 回答
2797 浏览

rust - 如何移动拥有的指针

作为参考,我使用的是 Rust 0.7。

我正在尝试使用拥有的链表创建堆栈实现,但遇到了麻烦。

当我尝试时,rustc stack.rs我收到以下错误:

我不知道我该如何克服这一点,或者我可以做些什么来允许这一点。看起来我应该能够在不使用托管指针的情况下创建这个数据结构,但是我还没有看到很多关于这类事情的文档。

0 投票
1 回答
580 浏览

rust - Semantics of moves of owned pointers

This article seems to imply the possibility that the use of the term "move" in the rust documentation doesn't mean copies, but transfer of ownership at compile time. See this quote specifically:

The compiler enforces that there is only a single owner. Assigning the pointer to a new location transfers ownership (known as a move for short). Consider this program:

Is this correct? are ownership transfers/moves not actually copies at runtime, but only a compile time abstraction.

0 投票
1 回答
841 浏览

rust - 如何在 rust 中管理可选的拥有指针?

我正在将我的一个 C++ 项目(一个简单的 DSL)转换为 rust 作为学习 rust 的练习,但我在嵌套结构和所有权方面遇到了麻烦。我很难转换一些东西,比如:

我要为此写的锈是:

这种代码的惯用生锈方式是什么?

0 投票
3 回答
1702 浏览

json - 无法摆脱取消引用

我正在学习 Rust 以及 extra::json 模块。这是我的示例(带有额外的不需要的类型注释):

当我编译时,我得到这个:

我还有其他使用 match 的示例不会遇到此错误。

谢谢你的帮助!