Skip to content

Commit

Permalink
test: using FromStr::Err: !Send+!Sync
Browse files Browse the repository at this point in the history
  • Loading branch information
chabapok committed Sep 30, 2023
1 parent cedbd4a commit 38db44b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,11 @@ name = "04_02_parse_derive"
path = "examples/tutorial_derive/04_02_parse.rs"
required-features = ["derive"]

[[example]]
name = "04_02_01_parse_from_str"
path = "examples/tutorial_derive/04_02_01_parse_from_str.rs"
required-features = ["derive"]

[[example]]
name = "04_02_validate_derive"
path = "examples/tutorial_derive/04_02_validate.rs"
Expand Down
46 changes: 46 additions & 0 deletions examples/tutorial_derive/04_02_01_parse_from_str.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use std::fmt::{Display, Formatter};
use std::marker::PhantomData;

#[derive(Clone, Debug)]
struct Foo {
foo: u32
}

impl std::str::FromStr for Foo {
type Err = NotSendSyncError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
if s=="error" {
Err(NotSendSyncError{_pd: PhantomData })
} else {
Ok(Foo{foo: 42})
}
}
}

#[derive(Debug)]
struct NotSendSyncError {
_pd: PhantomData<std::cell::RefCell<()>>,
}

impl Display for NotSendSyncError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
writeln!(f, "{:?}", self)
}
}

impl std::error::Error for NotSendSyncError {

}

#[derive(clap::Parser, Debug, Clone)]
#[structopt(name = "use FromStr")]
struct Config {
//#[arg(long, value_parser=clap::value_parser!(Foo))]
#[arg(long)]
foo: Foo
}

fn main() {
let config = <Config as clap::Parser>::parse();
}

0 comments on commit 38db44b

Please sign in to comment.