Skip to content

Commit

Permalink
Reducing test case further
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc committed Oct 1, 2021
1 parent ca3df60 commit b143608
Showing 1 changed file with 48 additions and 29 deletions.
77 changes: 48 additions & 29 deletions provider/core/src/struct_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,36 @@ where
}
}

trait MiniDataMarker<'data> {
type Yokeable: for<'a> Yokeable<'a>;
type Cart;
trait MiniYokeable<'a> {
type Output;
}

struct MiniDataPayload<'data, M> where M: MiniDataMarker<'data> {
pub yoke: Yoke<M::Yokeable, ()>,
struct MiniYoke<Y: for<'a> MiniYokeable<'a>> {
pub yokeable: Y,
}

impl<'data, M> Clone for MiniDataPayload<'data, M>
impl<Y> Clone for MiniYoke<Y>
where
M: MiniDataMarker<'data>,
for<'a> <M::Yokeable as Yokeable<'a>>::Output: Clone
Y: for<'a> MiniYokeable<'a>,
for<'a> <Y as MiniYokeable<'a>>::Output: Clone
{
fn clone(&self) -> Self {
todo!()
}
}

trait MiniDataMarker {
type Yokeable: for<'a> MiniYokeable<'a>;
}

struct MiniDataPayload<M> where M: MiniDataMarker {
pub yoke: MiniYoke<M::Yokeable>,
}

impl<M> Clone for MiniDataPayload<M>
where
M: MiniDataMarker,
for<'a> <M::Yokeable as MiniYokeable<'a>>::Output: Clone
{
fn clone(&self) -> Self {
Self {
Expand All @@ -80,47 +97,49 @@ where
}
}

trait MiniDataProvider<'data, M> where M: MiniDataMarker<'data> {
fn mini_load_payload(&self) -> MiniDataPayload<'data, M>;
trait MiniDataProvider<M> where M: MiniDataMarker {
fn mini_load_payload(&self) -> MiniDataPayload<M>;
}

struct MiniStructProvider<'data, M>
struct MiniStructProvider<M>
where
M: MiniDataMarker<'data>,
M: MiniDataMarker,
{
pub payload: MiniDataPayload<'data, M>,
pub payload: MiniDataPayload<M>,
}

impl<'data, M> MiniDataProvider<'data, M> for MiniStructProvider<'data, M>
impl<M> MiniDataProvider<M> for MiniStructProvider<M>
where
M: MiniDataMarker<'data>,
for<'a> <M::Yokeable as Yokeable<'a>>::Output: Clone,
M: MiniDataMarker,
for<'a> <M::Yokeable as MiniYokeable<'a>>::Output: Clone,
{
fn mini_load_payload(&self) -> MiniDataPayload<'data, M> {
fn mini_load_payload(&self) -> MiniDataPayload<M> {
self.payload.clone()
}
}

#[test]
fn test_traits() {
#[derive(Clone, yoke::Yokeable)]
struct SimpleStruct(pub u32);
#[derive(Clone, yoke::Yokeable)]
struct SimpleStruct(pub u32);

impl<'data> MiniDataMarker<'data> for SimpleStruct {
type Yokeable = SimpleStruct;
type Cart = SimpleStruct;
}
impl<'a> MiniYokeable<'a> for SimpleStruct {
type Output = SimpleStruct;
}

// A placeholder key to use to serve the data struct
const SAMPLE_KEY: ResourceKey = crate::resource_key!(x, "xyz", "example", 1);
impl MiniDataMarker for SimpleStruct {
type Yokeable = SimpleStruct;
}

#[test]
fn test_traits() {
let provider = MiniStructProvider {
payload: MiniDataPayload {
yoke: Yoke::new_always_owned(SimpleStruct(42))
yoke: MiniYoke {
yokeable: SimpleStruct(42)
}
}
};

let payload: MiniDataPayload<SimpleStruct> = provider.mini_load_payload();

assert_eq!(payload.yoke.get().0, 42);
assert_eq!(payload.yoke.yokeable.0, 42);
}

0 comments on commit b143608

Please sign in to comment.