相关疑难解决方法(0)

如何将使用三元运算符的C++代码移植到Rust?

如何将此C++代码移植到Rust:

auto sgnR = (R >= 0.) ? 1. : -1.;
Run Code Online (Sandbox Code Playgroud)

我看过match关键字的一些例子,但我不明白它是如何工作的.

if-statement conditional-operator rust

12
推荐指数
2
解决办法
2900
查看次数

如何在 Rust 代码中表示 C 的“无符号负”值?

我正在ResumeThread使用winapi crate从 Rust调用WinAPI 函数。

文档说:

如果函数成功,则返回值是线程先前的挂起计数。

如果函数失败,则返回值是 (DWORD) -1。

如何有效地检查是否有错误?

在 C 中:

if (ResumeThread(hMyThread) == (DWORD) -1) {
    // There was an error....
}
Run Code Online (Sandbox Code Playgroud)

在 Rust 中:

unsafe {
    if ResumeThread(my_thread) == -1 {
            // There was an error....
    }
}
Run Code Online (Sandbox Code Playgroud)
unsafe {
    if ResumeThread(my_thread) == -1 {
            // There was an error....
    }
}
Run Code Online (Sandbox Code Playgroud)

我理解错误;但是在语义上与 C 代码相同的最佳方式是什么?对照std::u32::MAX?

ffi signedness rust

2
推荐指数
1
解决办法
210
查看次数