diff options
author | SoniEx2 <endermoneymod@gmail.com> | 2021-12-05 00:11:33 -0300 |
---|---|---|
committer | SoniEx2 <endermoneymod@gmail.com> | 2021-12-05 00:11:33 -0300 |
commit | 70137e6614843c42dd9ad32abf00e5fc7da7662f (patch) | |
tree | b4fc40f6e6c3174c29958e33b94729e27b108c2f /src/args.rs | |
parent | b4bbe8a7733ce8f45cbd0d9b337ce3cb29f75e98 (diff) |
Add more Send + Sync
Diffstat (limited to 'src/args.rs')
-rw-r--r-- | src/args.rs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/args.rs b/src/args.rs index 8647ea7..10b8fea 100644 --- a/src/args.rs +++ b/src/args.rs @@ -26,7 +26,14 @@ use crate::suggestion::SuggestionsBuilder; /// The parsing context of a command. pub struct CommandContext<'i, S, E>(::std::marker::PhantomData<(&'i str, S, E)>); -/// An argument parser. +/// An argument parser/validator. +/// +/// Note: Iosonism requires arguments to be `Send + Sync`, but for ease when +/// implementing generic argument types, those bounds are not reflected in this +/// trait. Nevertheless, Iosonism doesn't itself use threads, so a [workaround] +/// can be used if one needs non-`Send + Sync` argument types. +/// +/// [workaround]: https://users.rust-lang.org/t/how-to-check-send-at-runtime-similar-to-how-refcell-checks-borrowing-at-runtime/68269 /// /// # Type params /// @@ -86,7 +93,7 @@ pub trait ArgumentType<S, E> { } /// Wrapper around `ArgumentType`, but with `Any`. -pub(crate) trait ArgumentTypeAny<S, E> { +pub(crate) trait ArgumentTypeAny<S, E>: Send + Sync { /// Parses an argument of this type, returning the parsed argument. fn parse<'i>( &self, @@ -104,7 +111,7 @@ pub(crate) trait ArgumentTypeAny<S, E> { fn get_examples(&self) -> Cow<'static, [&str]>; } -impl<T: ArgumentType<S, E>, S, E> ArgumentTypeAny<S, E> for T { +impl<T: ArgumentType<S, E> + Send + Sync, S, E> ArgumentTypeAny<S, E> for T { fn parse<'i>( &self, reader: &mut Cursor<&'i str>, |