Experiment with futures
This commit is contained in:
parent
907fbf95db
commit
2d3e3688fa
44 changed files with 2081 additions and 1242 deletions
|
|
@ -218,28 +218,51 @@ impl<D> Resource for Cron<D> {
|
|||
type Artifact = ();
|
||||
}
|
||||
|
||||
pub trait BorrowResource<R> {
|
||||
fn borrow_resource(&self) -> Option<&R>;
|
||||
use std::rc::{Rc, Weak};
|
||||
|
||||
pub trait FromResource<R> {
|
||||
fn from_resource(from: R) -> (Self, Weak<R>)
|
||||
where
|
||||
Self: Sized;
|
||||
}
|
||||
|
||||
pub trait FromArtifact<R: Resource> {
|
||||
fn from_artifact(from: R::Artifact) -> Self
|
||||
where
|
||||
Self: Sized;
|
||||
fn into_artifact(self) -> R::Artifact
|
||||
where
|
||||
Self: Sized;
|
||||
}
|
||||
|
||||
macro_rules! default_resources {
|
||||
( $($name:ident: $type:ty,)* ) => {
|
||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||
pub enum DefaultResources<'a, D> {
|
||||
$( $name($type) ),*
|
||||
$( $name(Rc<$type>) ),*
|
||||
}
|
||||
|
||||
$(impl<'a, D> From<$type> for DefaultResources<'a, D> {
|
||||
fn from(from: $type) -> Self {
|
||||
Self::$name(from)
|
||||
$(impl<'a, D> FromResource<$type> for DefaultResources<'a, D> {
|
||||
fn from_resource(from: $type) -> (Self, Weak<$type>) {
|
||||
let inner = Rc::new(from);
|
||||
(Self::$name(Rc::clone(&inner)), Rc::downgrade(&inner))
|
||||
}
|
||||
})*
|
||||
|
||||
$(impl<'a, D> BorrowResource<$type> for DefaultResources<'a, D> {
|
||||
fn borrow_resource(&self) -> Option<&$type> {
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum DefaultArtifacts<'a, D> {
|
||||
$( $name(<$type as Resource>::Artifact) ),*
|
||||
}
|
||||
|
||||
$(impl<'a, D> FromArtifact<$type> for DefaultArtifacts<'a, D> {
|
||||
fn from_artifact(from: <$type as Resource>::Artifact) -> Self {
|
||||
Self::$name(from)
|
||||
}
|
||||
|
||||
fn into_artifact(self) -> <$type as Resource>::Artifact {
|
||||
match self {
|
||||
Self::$name(v) => Some(v),
|
||||
_ => None
|
||||
Self::$name(inner) => inner,
|
||||
_ => panic!()
|
||||
}
|
||||
}
|
||||
})*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue