pub struct Dispatcher { /* private fields */ }Implementations§
Source§impl Dispatcher
impl Dispatcher
Sourcepub fn new<H: Into<BoxSafeRunnableCommand>>(h: H) -> Result<Self, Error>
pub fn new<H: Into<BoxSafeRunnableCommand>>(h: H) -> Result<Self, Error>
Examples found in repository?
examples/simple.rs (line 38)
37async fn main() -> anyhow::Result<()> {
38 let dispatcher = Dispatcher::new(RootCommand::default())?.register(HiCommand::default())?;
39 // dispatcher.dispatch_with_stdio().await?;
40 let buf = vec![];
41 let w = tokio::io::BufWriter::new(buf);
42 let w = std::sync::Arc::new(tokio::sync::Mutex::new(w));
43 let _cx = dispatcher
44 .dispatch(&["rt", "--debug", "hi", "--name", "me"], w.clone())
45 .await?;
46 w.lock().await.flush().await?;
47 let output = String::from_utf8(w.lock().await.get_ref().to_owned())?;
48 debug_assert_eq!(output, "hi me");
49 println!("{}", output);
50 Ok(())
51}Sourcepub fn register<H: Into<BoxSafeRunnableCommand>>(
self,
h: H,
) -> Result<Self, Error>
pub fn register<H: Into<BoxSafeRunnableCommand>>( self, h: H, ) -> Result<Self, Error>
Examples found in repository?
examples/simple.rs (line 38)
37async fn main() -> anyhow::Result<()> {
38 let dispatcher = Dispatcher::new(RootCommand::default())?.register(HiCommand::default())?;
39 // dispatcher.dispatch_with_stdio().await?;
40 let buf = vec![];
41 let w = tokio::io::BufWriter::new(buf);
42 let w = std::sync::Arc::new(tokio::sync::Mutex::new(w));
43 let _cx = dispatcher
44 .dispatch(&["rt", "--debug", "hi", "--name", "me"], w.clone())
45 .await?;
46 w.lock().await.flush().await?;
47 let output = String::from_utf8(w.lock().await.get_ref().to_owned())?;
48 debug_assert_eq!(output, "hi me");
49 println!("{}", output);
50 Ok(())
51}pub async fn dispatch_with_stdio(self) -> Result<Context, Error>
Sourcepub async fn dispatch<I, T, O>(
self,
i: I,
o: Arc<Mutex<O>>,
) -> Result<Context, Error>
pub async fn dispatch<I, T, O>( self, i: I, o: Arc<Mutex<O>>, ) -> Result<Context, Error>
Examples found in repository?
examples/simple.rs (line 44)
37async fn main() -> anyhow::Result<()> {
38 let dispatcher = Dispatcher::new(RootCommand::default())?.register(HiCommand::default())?;
39 // dispatcher.dispatch_with_stdio().await?;
40 let buf = vec![];
41 let w = tokio::io::BufWriter::new(buf);
42 let w = std::sync::Arc::new(tokio::sync::Mutex::new(w));
43 let _cx = dispatcher
44 .dispatch(&["rt", "--debug", "hi", "--name", "me"], w.clone())
45 .await?;
46 w.lock().await.flush().await?;
47 let output = String::from_utf8(w.lock().await.get_ref().to_owned())?;
48 debug_assert_eq!(output, "hi me");
49 println!("{}", output);
50 Ok(())
51}Auto Trait Implementations§
impl Freeze for Dispatcher
impl !RefUnwindSafe for Dispatcher
impl !Send for Dispatcher
impl !Sync for Dispatcher
impl Unpin for Dispatcher
impl !UnwindSafe for Dispatcher
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more