Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![allow(dead_code)]
- use std::marker::PhantomData;
- trait Abc {}
- struct ImplAbc;
- impl Abc for ImplAbc {}
- struct WrappingAbc<'a, A: Abc> {
- value: &'a A,
- }
- impl<'a, A: Abc> Abc for WrappingAbc<'a, A> {}
- impl<'a, A: Abc> WrappingAbc<'a, A> {
- fn new(value: &'a A) -> Self {
- WrappingAbc { value, }
- }
- }
- struct AnotherWrapper<'a, K: Kind, A: Abc, S> {
- value: &'a A,
- other: usize,
- phantom_data: PhantomData<(K, S)>,
- }
- impl<'a, K: Kind, A: Abc, S: Strategy<K, A>> AnotherWrapper<'a, K, A, S> {
- fn new(value: &'a A) -> Self {
- AnotherWrapper {
- value,
- other: 0,
- phantom_data: PhantomData,
- }
- }
- }
- impl<'a, 'b, A: Abc, S: Strategy<KindTwo, A>> AnotherWrapper<'a, KindTwo, WrappingAbc<'b, A>, S> {
- fn replace_value(
- old: AnotherWrapper<KindOne, A, S>,
- newvalue: &'a WrappingAbc<'b, A>,
- ) -> Self {
- AnotherWrapper {
- value: newvalue,
- other: old.other,
- phantom_data: PhantomData,
- }
- }
- }
- trait Kind {}
- struct KindOne;
- impl Kind for KindOne {}
- struct KindTwo;
- impl Kind for KindTwo {}
- trait Strategy<K: Kind, A: Abc>: Sized {}
- struct StrategyImpl;
- impl<K: Kind, A: Abc> Strategy<K, A> for StrategyImpl {}
- fn f<'a, A: Abc>(x: &'a A) {
- let first = AnotherWrapper::<KindOne, A, StrategyImpl>::new(x);
- let wrapper = WrappingAbc::new(x);
- let second = AnotherWrapper::replace_value(first, &wrapper);
- move_away(second);
- }
- fn move_away<'a, A: Abc, S: Strategy<KindTwo, A>>(_argument: AnotherWrapper<'a, KindTwo, A, S>) {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement