Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save federicomenaquintero/511ee376e3010ecfcfff6077ecdfca0a to your computer and use it in GitHub Desktop.
Save federicomenaquintero/511ee376e3010ecfcfff6077ecdfca0a to your computer and use it in GitHub Desktop.
pub struct Node<'a> {
node_type: NodeType,
parent: RefCell<Option<Weak<Node<'a>>>>, // cell for interior mutability; optional; weak ref to parent
children: Vec<Rc<Node<'a>>>, // strong references to children
state: *mut RsvgState,
node_impl: &'a NodeTrait
}
impl<'a> Node<'a> {
// ...
pub fn add_child (&mut self, child: &Rc<Node<'a>>) {
self.children.push (child.clone ());
}
}
type RsvgRcNode<'a> = Rc<Node<'a>>;
#[no_mangle]
pub extern fn rsvg_node_add_child<'a> (raw_node: *mut RsvgRcNode<'a>, raw_child: *const RsvgRcNode<'a>) {
assert! (!raw_node.is_null ());
let rc_node: &mut RsvgRcNode<'a> = unsafe { &mut *raw_node };
let rc_child: &RsvgRcNode<'a> = unsafe { & *raw_child };
rc_node.add_child (rc_child);
}
error: cannot borrow immutable borrowed content as mutable
--> node.rs:160:5
|
160 | rc_node.add_child (rc_child);
| ^^^^^^^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment