From 70137e6614843c42dd9ad32abf00e5fc7da7662f Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Sun, 5 Dec 2021 00:11:33 -0300 Subject: Add more Send + Sync --- src/args.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/args.rs') 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 { } /// Wrapper around `ArgumentType`, but with `Any`. -pub(crate) trait ArgumentTypeAny { +pub(crate) trait ArgumentTypeAny: Send + Sync { /// Parses an argument of this type, returning the parsed argument. fn parse<'i>( &self, @@ -104,7 +111,7 @@ pub(crate) trait ArgumentTypeAny { fn get_examples(&self) -> Cow<'static, [&str]>; } -impl, S, E> ArgumentTypeAny for T { +impl + Send + Sync, S, E> ArgumentTypeAny for T { fn parse<'i>( &self, reader: &mut Cursor<&'i str>, -- cgit 1.4.1