如何将此C++代码移植到Rust:
auto sgnR = (R >= 0.) ? 1. : -1.;
Run Code Online (Sandbox Code Playgroud)
我看过match关键字的一些例子,但我不明白它是如何工作的.
我正在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?