Movatterモバイル変換


[0]ホーム

URL:


todo

std

Macrotodo 

1.40.0 ·Source
macro_rules! todo {    () => { ... };    ($($arg:tt)+) => { ... };}
Expand description

Indicates unfinished code.

This can be useful if you are prototyping and justwant a placeholder to let your code pass type analysis.

The difference betweenunimplemented! andtodo! is that whiletodo! conveysan intent of implementing the functionality later and the message is “not yetimplemented”,unimplemented! makes no such claims. Its message is “not implemented”.

Also, some IDEs will marktodo!s.

§Panics

This will alwayspanic! becausetodo! is just a shorthand forpanic! with afixed, specific message.

Likepanic!, this macro has a second form for displaying custom values.

§Examples

Here’s an example of some in-progress code. We have a traitFoo:

traitFoo {fnbar(&self) -> u8;fnbaz(&self);fnqux(&self) ->Result<u64, ()>;}

We want to implementFoo on one of our types, but we also want to work onjustbar() first. In order for our code to compile, we need to implementbaz() andqux(), so we can usetodo!:

structMyStruct;implFooforMyStruct {fnbar(&self) -> u8 {1+1}fnbaz(&self) {// Let's not worry about implementing baz() for nowtodo!();    }fnqux(&self) ->Result<u64, ()> {// We can add a message to todo! to display our omission.        // This will display:        // "thread 'main' panicked at 'not yet implemented: MyStruct is not yet quxable'".todo!("MyStruct is not yet quxable");    }}fnmain() {lets = MyStruct;    s.bar();// We aren't even using baz() or qux(), so this is fine.}

[8]ページ先頭

©2009-2026 Movatter.jp