1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#![ cfg_attr( nightly, feature(doc_cfg) ) ]
#![ doc = include_str!("../README.md") ]

#![ doc    ( html_root_url = "https://docs.rs/thespis_impl" ) ]
#![ deny   ( missing_docs                                   ) ]
#![ forbid ( unsafe_code                                    ) ]
#![ allow  ( clippy::suspicious_else_formatting             ) ]

#![ warn
(
	anonymous_parameters          ,
	missing_copy_implementations  ,
	missing_debug_implementations ,
	missing_docs                  ,
	nonstandard_style             ,
	rust_2018_idioms              ,
	single_use_lifetimes          ,
	trivial_casts                 ,
	trivial_numeric_casts         ,
	unreachable_pub               ,
	unused_extern_crates          ,
	unused_qualifications         ,
	variant_size_differences      ,
)]

mod actor_builder ;
mod actor_info    ;
mod addr          ;
mod addr_inner    ;
mod envelope      ;
mod error         ;
mod mailbox       ;
mod rx_strong     ;
mod strong_count  ;
mod weak_addr     ;


pub use
{
	actor_builder :: * ,
	actor_info    :: * ,
	addr          :: * ,
	error         :: * ,
	mailbox       :: * ,
 	weak_addr     :: * ,

	// Addr::send requires SinkExt, so let's re-export that.
	//
	futures::{ SinkExt },
};

pub(crate) use
{
	strong_count ::* ,
	rx_strong    ::* ,
};

use futures::Sink;


/// Shorthand for a `Send` boxed envelope.
//
pub type BoxEnvelope<A> = Box< dyn envelope::Envelope<A> + Send >;

/// A boxed error type for the sink
//
pub type DynError = Box< dyn std::error::Error + Send + Sync >;

/// Type of boxed channel sender for Addr.
//
pub type ChanSender<A> = Box< dyn CloneSink<'static, BoxEnvelope<A>, DynError> >;

/// Type of boxed channel receiver for Mailbox.
//
pub type ChanReceiver<A> = Box< dyn futures::Stream<Item=BoxEnvelope<A>> + Send + Unpin >;


/// Interface for T: Sink + Clone
//
pub trait CloneSink<'a, Item, E>: Sink<Item, Error=E> + Unpin + Send
{
	/// Clone this sink.
	//
	fn clone_sink( &self ) -> Box< dyn CloneSink<'a, Item, E> + 'a >;
}


impl<'a, T, Item, E> CloneSink<'a, Item, E> for T

	where T: 'a + Sink<Item, Error=E> + Clone + Unpin + Send + ?Sized

{
	fn clone_sink( &self ) -> Box< dyn CloneSink<'a, Item, E> + 'a >
	{
		Box::new( self.clone() )
	}
}



// Import module. Avoid * imports here. These are all the foreign names that exist throughout
// the crate. The must all be unique.
// Separate use imports per enabled features.
//
mod import
{
	pub(crate) use
	{
		thespis         :: { * } ,
		tracing         :: { trace, debug, error, error_span, Span } ,
		tracing_futures :: { Instrument } ,
		async_executors :: { SpawnHandle, SpawnHandleExt, LocalSpawnHandle, LocalSpawnHandleExt, JoinHandle } ,

		std ::
		{
			fmt                                                          ,
			error   :: { Error                                         } ,
			convert :: { TryFrom                                       } ,
			pin     :: { Pin                                           } ,
			sync    :: { Arc, Mutex, atomic::{ AtomicUsize, Ordering } } ,
			panic   :: { AssertUnwindSafe                              } ,
			task    :: { Context as TaskContext, Poll                  } ,
		},


		futures ::
		{
			stream  :: { Stream, StreamExt                                      } ,
			sink    :: { Sink, SinkExt                                          } ,
			future  :: { FutureExt                                              } ,
			task    :: { Spawn, SpawnExt, LocalSpawn, LocalSpawnExt, SpawnError } ,
		},

		oneshot::{ channel as oneshot, Sender as OneSender } ,
	};
}