Skip to content

Instantly share code, notes, and snippets.

// Goal of this file:
// Figure out in which cases a "move" or a "borrow" operation is performed
// by the rust compiler.
//
// Finding:
// - A "simple" assignment without defining the type on the local variable
// cause the field to be moved:
//
// let id_ref = entry.id; // entry.id is moved!
//

Rust Borrow Rules Overview

NOTE: The rules shown here do not take the lifetime constraints into account. The rules could be easily adapted to cover the lifetimes as well but this is not done for similicty at this point.

How to read the following:

The operations on the objects and fiels are denoted as follows:

Rust Borrow Rules

NOTE: The rules shown here do not take the lifetime constraints into account. The rules could be easily adapted to cover the lifetimes as well but this is not done for similicty at this point.

How to read the following:

The operations on the objects and fiels are denoted as follows:

Rust Borrow Rules

NOTE: The rules shown here do not take the lifetime constraints into account. The rules could be easily adapted to cover the lifetimes as well but this is not done for similicty at this point.

How to read the following:

The operations on the objects and fiels are denoted as follows:

Rust Borrow Rules

NOTE: The rules shown here do not take the lifetime constraints into account. The rules could be easily adapted to cover the lifetimes as well but this is not done for similicty at this point.

How to read the following:

The operations on the objects and fiels are denoted as follows:

'use strict';
var React = require('react');
// EXAMPLE:
//
// var ExampleComponent = React.createClass({
// render(): any {
// // Define the CSS content used by this component.
// var styleContent = `
pub struct RefList<T: 'local> {
// Use this arena to create the node elements in the list.
node_arena: TypedArena<T>
// Store the last object allocated from the `node_arean` in this field.
list_tail: Option<&'local mut T>,
}
impl<T> RefList<T: 'local> {
fn new(capacity: usize) -> RefList<T> {
struct Entry<T>{
value: T
}
// error: the parameter type `T` may not live long enough [E0309]
struct Container<'a, T> {
counter: usize,
body: Option<&'a mut Entry<T>>
}
➜ acorn-babel git:(master5) ✗ diff acorn_csp.js acorn_csp_mod.js
4127a4128,4139
> function parseJSXStyle() {
> var node = startNode();
> var initialTokenStart = tokStart;
>
> while (tokType !== _jsxTagStart) { next(); }
>
> var val = input.slice(initialTokenStart, tokStart);
> node.value = val;
fn print_node_id(node_ref: &Node) {
println!("node.id={}", node_ref.id);
match node_ref.next {
Some(ref next) => {
println!("node.next.id={}", next.id);
}
None => {
println!("node.next=None");
}