1.0.0[][src]Macro std::unimplemented

macro_rules! unimplemented {
    () => { ... };
    ($ ($ arg : tt) +) => { ... };

Indicates unfinished code by panicking with a message of "not yet implemented".

This allows the your code to type-check, which is useful if you are prototyping or implementing a trait that requires multiple methods which you don't plan of using all of.

There is no difference between unimplemented! and todo! apart from the name.


This will always panic! because unimplemented! is just a shorthand for panic! with a fixed, specific message.

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


Here's an example of some in-progress code. We have a trait Foo:

trait Foo {
    fn bar(&self) -> u8;
    fn baz(&self);
    fn qux(&self) -> Result<u64, ()>;

We want to implement Foo for 'MyStruct', but so far we only know how to implement the bar() function. baz() and qux() will still need to be defined in our implementation of Foo, but we can use unimplemented! in their definitions to allow our code to compile.

In the meantime, we want to have our program stop running once these unimplemented functions are reached.

struct MyStruct;

impl Foo for MyStruct {
    fn bar(&self) -> u8 {
        1 + 1

    fn baz(&self) {
        // We aren't sure how to even start writing baz yet,
        // so we have no logic here at all.
        // This will display "thread 'main' panicked at 'not yet implemented'".

    fn qux(&self) -> Result<u64, ()> {
        let n = self.bar();
        // We have some logic here,
        // so we can use unimplemented! to display what we have so far.
        // This will display:
        // "thread 'main' panicked at 'not yet implemented: we need to divide by 2'".
        unimplemented!("we need to divide by {}", n);

fn main() {
    let s = MyStruct;