Macro core::todo 1.40.0[−][src]
macro_rules! todo {
() => { ... };
($($arg : tt) +) => { ... };
}Expand description
表示未完成的代码。
如果您要进行原型设计并且只是在检查代码类型,这可能会很有用。
unimplemented! 和 todo! 之间的区别在于,尽管 todo! 传达了稍后实现该功能的意图,并且消息为 “not yet implemented”,但 unimplemented! 并未提出任何此类声明。
它的消息是 “not implemented”。
还有一些 IDE 会标记 todo!。
Panics
这将始终为 panic!。
Examples
这是一些正在进行的代码的示例。我们有一个 Foo trait:
trait Foo {
fn bar(&self);
fn baz(&self);
}Run我们想在其中一种类型上实现 Foo,但我们也想首先仅在 bar() 上工作。为了编译我们的代码,我们需要实现 baz(),因此我们可以使用 todo!:
struct MyStruct;
impl Foo for MyStruct {
fn bar(&self) {
// 实现在这里
}
fn baz(&self) {
// 让我们现在不必担心实现 baz()
todo!();
}
}
fn main() {
let s = MyStruct;
s.bar();
// 我们甚至没有使用 baz(),所以很好。
}Run