2014-12-07 15:22:06 +00:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2014-12-22 17:04:23 +00:00
|
|
|
use std::ops::Deref;
|
|
|
|
|
2014-12-07 15:22:06 +00:00
|
|
|
struct Root {
|
|
|
|
jsref: JSRef
|
|
|
|
}
|
|
|
|
|
2015-01-01 19:53:20 +00:00
|
|
|
impl Deref for Root {
|
|
|
|
type Target = JSRef;
|
|
|
|
|
2014-12-07 15:22:06 +00:00
|
|
|
fn deref<'a>(&'a self) -> &'a JSRef {
|
|
|
|
&self.jsref
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-30 13:38:27 +00:00
|
|
|
#[derive(Copy, Clone)]
|
2014-12-07 15:22:06 +00:00
|
|
|
struct JSRef {
|
|
|
|
node: *const Node
|
|
|
|
}
|
|
|
|
|
2015-01-01 19:53:20 +00:00
|
|
|
impl Deref for JSRef {
|
|
|
|
type Target = Node;
|
|
|
|
|
2014-12-07 15:22:06 +00:00
|
|
|
fn deref<'a>(&'a self) -> &'a Node {
|
|
|
|
self.get()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
trait INode {
|
|
|
|
fn RemoveChild(&self);
|
|
|
|
}
|
|
|
|
|
|
|
|
impl INode for JSRef {
|
|
|
|
fn RemoveChild(&self) {
|
|
|
|
self.get().RemoveChild(0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl JSRef {
|
|
|
|
fn AddChild(&self) {
|
|
|
|
self.get().AddChild(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get<'a>(&'a self) -> &'a Node {
|
|
|
|
unsafe {
|
|
|
|
&*self.node
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Node;
|
|
|
|
|
|
|
|
impl Node {
|
2015-03-26 00:06:52 +00:00
|
|
|
fn RemoveChild(&self, _a: usize) {
|
2014-12-07 15:22:06 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
fn AddChild(&self, _a: usize) {
|
2014-12-07 15:22:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let n = Node;
|
|
|
|
let jsref = JSRef { node: &n };
|
|
|
|
let root = Root { jsref: jsref };
|
|
|
|
|
|
|
|
root.AddChild();
|
|
|
|
jsref.AddChild();
|
|
|
|
|
|
|
|
root.RemoveChild();
|
|
|
|
jsref.RemoveChild();
|
|
|
|
}
|