-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: using FromStr::Err: !Send+!Sync
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |