small update

new
Avril 4 years ago
parent 0ec606cf39
commit 8ca16772c6
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -218,12 +218,38 @@ static_assert!(1+1==2; "static assertion test");
}; };
} }
/// Run each expression in sequence then return the result of the first one.
///
/// # Example
/// ```
/// # use mtfse::prog1;
/// assert_eq!(prog1 {
/// 1 + 2;
/// println!("Done thing");
/// 4 + 5;
/// }, 3);
/// ```
#[macro_export] macro_rules! prog1 { #[macro_export] macro_rules! prog1 {
($first:expr, $($rest:expr);+ $(;)?) => { ($first:expr; $($rest:expr);* $(;)?) => {
($first, $( $rest ),+).0 ($first, $( $rest ),*).0
} }
} }
/// Helper to create an `std::io::Error` structure.
///
/// # Example
/// ```
/// # use mtfse::io_err;
/// let err = io_err!(Other, "some error");
/// ```
#[macro_export] macro_rules! io_err {
($kind:ident, $msg:expr) => {
::std::io::Error::new(::std::io::ErrorKind::$kind, $msg)
};
($msg:expr) => (io_err!(Other, $msg));
}
pub trait UnwrapInfallible<T> pub trait UnwrapInfallible<T>
{ {

@ -15,13 +15,6 @@ use jemallocator::Jemalloc;
#[global_allocator] #[global_allocator]
static GLOBAL: Jemalloc = Jemalloc; static GLOBAL: Jemalloc = Jemalloc;
macro_rules! io_err {
($kind:ident, $msg:expr) => {
::std::io::Error::new(::std::io::ErrorKind::$kind, $msg)
};
($msg:expr) => (io_err!(Other, $msg));
}
// Utils // Utils
mod ext; mod ext;
use ext::*; use ext::*;

@ -30,6 +30,7 @@ pub struct Command
resp: oneshot::Receiver<Option<Response>>, resp: oneshot::Receiver<Option<Response>>,
} }
impl fmt::Display for Command impl fmt::Display for Command
{ {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result

@ -6,11 +6,16 @@ use tokio::sync::{
Mutex, Mutex,
mpsc, mpsc,
oneshot,
}; };
pub mod command; pub mod command;
use command::{
CommandKind,
CommandID,
};
/// Handle to a running service /// Handle to a running service. Can be used to join it or create `Channel`s.
#[derive(Debug)] #[derive(Debug)]
pub struct Handle pub struct Handle
{ {
@ -18,21 +23,38 @@ pub struct Handle
} }
#[derive(Debug)] #[derive(Debug)]
struct CommInner struct ChannelInner
{ {
} }
/// Communicate with a running service
/// The side of a `command::Command` that the running service sees.
#[derive(Debug)]
struct Request
{
/// ID that corresponds to the returned `command::Command` from the `send()` function of `Channel`.
id: CommandID,
/// The actual command sent by the user.
kind: CommandKind,
/// Optional response sender.
///
/// Just dropping this is the same as sending `None` as far as the user sees.
resp: oneshot::Sender<Option<command::Response>>,
}
/// Communicates with a running service
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Comm{ pub struct Channel{
inner: Arc<CommInner>, inner: Arc<ChannelInner>,
tx: mpsc::Sender<()>, tx: mpsc::Sender<Request>,
} }
impl Eq for Comm{} impl Eq for Channel{}
impl PartialEq for Comm { impl PartialEq for Channel {
#[inline] fn eq(&self, other: &Self) -> bool #[inline] fn eq(&self, other: &Self) -> bool
{ {
Arc::ptr_eq(&self.inner, &other.inner) Arc::ptr_eq(&self.inner, &other.inner)

Loading…
Cancel
Save