async_executors 0.4.1

Implements Spawn, SpawnLocal and SpawnHandle for commonly used executors.
Documentation
//! Provides TokioCtBuilder which guarantees at type level that it is single-threaded.
//
use
{
	crate :: { TokioCt                          } ,
	std   :: { sync::Arc                        } ,
	tokio :: { task::LocalSet, runtime::Builder } ,
};


/// Builder to create a [`TokioCt`] executor. This guarantees that `TokioCt` always has a runtime that is single-threaded,
/// as tokio does not make this information available on it's `Runtime` type.
///
/// Further allows you access to the tokio builder so you can set the other configuration options on it as you see fit.
//
#[ derive(Debug) ]
//
pub struct TokioCtBuilder
{
	builder: Builder,
}



impl TokioCtBuilder
{
	/// Constructor.
	//
	pub fn new() -> Self
	{
		Self
		{
			builder: Builder::new_current_thread(),
		}
	}


	/// Returns the builder from tokio so you can configure it, see: [Builder].
	/// If you `mem::swap` it, your warranty is void.
	//
	pub fn tokio_builder( &mut self ) -> &mut Builder
	{
		&mut self.builder
	}


	/// Create the actual executor.
	///
	/// The error comes from tokio. From their docs, no idea why it is there or what could go wrong.
	//
	pub fn build( &mut self ) -> Result<TokioCt, std::io::Error>
	{
		let exec = self.builder.build()?;

		Ok( TokioCt
		{
			exec : Arc::new( exec            ) ,
			local: Arc::new( LocalSet::new() ) ,
		})
	}
}


impl Default for TokioCtBuilder
{
	fn default() -> Self
	{
		Self::new()
	}
}