Created
December 11, 2015 19:45
-
-
Save anonymous/0cbea83ee7fc018260ef to your computer and use it in GitHub Desktop.
Shared via Rust Playground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![allow(dead_code, unused_variables, unused_imports)] | |
#![feature(placement_in_syntax, placement_new_protocol)] | |
#![allow(unused_parens)] | |
use std::cell::Cell; | |
struct LeftHandSide<X, Y> { a: Option<X>, b: Option<Y> } | |
struct A(i32); | |
#[derive(Debug)] | |
struct B(i32); | |
#[derive(Debug)] | |
struct Kernel(i32); | |
impl Kernel { | |
fn build_a_b(self) -> B { | |
println!("Building a B from {:?}", self); | |
B(self.0) | |
} | |
} | |
use std::ops::{Place, Placer, InPlace}; | |
struct LhsPlace { | |
k: Kernel | |
} | |
impl Placer<Kernel> for LeftHandSide<A, B> { | |
type Place = LhsPlace; | |
fn make_place(self) -> Self::Place { | |
println!("allocating a place"); | |
LhsPlace { k: Kernel(0) } | |
} | |
} | |
impl Place<Kernel> for LhsPlace { | |
fn pointer(&mut self) -> *mut Kernel { | |
let p: *mut Kernel = &mut self.k; | |
println!("LhsPlace: Handing pointer {:?} off", p); | |
p | |
} | |
} | |
impl InPlace<Kernel> for LhsPlace { | |
type Owner = B; | |
unsafe fn finalize(self) -> B { | |
self.k.build_a_b() | |
} | |
} | |
fn main() { | |
let lhs = LeftHandSide { a: Some(A(0)), b: Some(B(0)) }; | |
println!("right before placement expr"); | |
let b = (lhs <- Kernel(10+10)); | |
println!("got here! b: {:?}", b); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment