Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

Support newtype pattern #184

Open
dbrgn opened this issue May 6, 2016 · 0 comments
Open

Support newtype pattern #184

dbrgn opened this issue May 6, 2016 · 0 comments

Comments

@dbrgn
Copy link

dbrgn commented May 6, 2016

Looks like deserializing newtypes is not supported yet.

Code to reproduce:

extern crate docopt;
extern crate rustc_serialize;

use docopt::Docopt;

static USAGE: &'static str = "
Usage: cli_client [-i ID]

Options:
    -i ID  A client id.
";

#[derive(RustcDecodable, Debug)]
pub struct ClientId(pub u32);

#[derive(RustcDecodable, Debug)]
struct Args {
    flag_i: Option<ClientId>,
}

fn main() {
    println!("Hello, world!");
    let args: Args = Docopt::new(USAGE).and_then(|d| d.decode())
                                       .unwrap_or_else(|e| e.exit());
    println!("{:?}", args);
}

Running this without arguments works:

[master]danilo@t410:test$ cargo run
     Running `target/debug/test`
Hello, world!
Args { flag_i: None }

But when specifying an argument, parsing fails:

[master]danilo@t410:test$ cargo run -- -i 123
     Running `target/debug/test -i 123`
Hello, world!
thread '<main>' panicked at 'Unrecognized struct field: '_field0'', /home/danilo/.multirust/toolchains/stable/cargo/registry/src/github.com-88ac128001ac3a9a/docopt-0.6.80/src/dopt.rs:481
note: Run with `RUST_BACKTRACE=1` for a backtrace.
Process didn't exit successfully: `target/debug/test -i 123` (exit code: 101)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant