Consider the following code:
#![allow(dead_code)]
fn f (x: &mut i32) -> &mut i32 { x }
fn id<T>(x: T ) -> T { x }
fn main() {
let mut x = 10;
let m = &mut x;
Consider the following code:
#![allow(dead_code)]
fn f (x: &mut i32) -> &mut i32 { x }
fn id<T>(x: T ) -> T { x }
fn main() {
let mut x = 10;
let m = &mut x;
//! Generators in Rust, simulated at great expense using threads | |
//! | |
//! Here's a generator which yields the numbers from one to three: | |
//! | |
//! let gen = generate(|(), out| { | |
//! for i in 1..4 { | |
//! out.yield_(i); | |
//! } | |
//! }); | |
//! |
/* barriers.h --- interface to memory and code translation barriers */ | |
#ifndef MN__GC_BARRIERS_H | |
#define MN__GC_BARRIERS_H | |
/* The following two functions provide the memory-coherence behavior | |
of mutexes, but without any blocking or communication. | |
On many modern multi-threaded systems, one thread may see writes to |
5828: 49 83 fa ff cmp $0xffffffffffffffff,%r10 | |
582c: 74 5d je 588b <_ZN8triangle4main17h1e5682daf508becbE+0x11b> | |
582e: 49 8d 42 ff lea -0x1(%r10),%rax | |
5832: 49 f7 e2 mul %r10 | |
5835: 49 89 c0 mov %rax,%r8 | |
5838: 49 89 d1 mov %rdx,%r9 | |
583b: 49 8d 72 fe lea -0x2(%r10),%rsi | |
583f: 48 f7 e6 mul %rsi | |
5842: 48 89 c7 mov %rax,%rdi | |
5845: 48 89 d3 mov %rdx,%rbx |
5830: 48 8d 47 ff lea -0x1(%rdi),%rax | |
5834: 48 f7 e7 mul %rdi | |
5837: 48 89 c1 mov %rax,%rcx | |
583a: 48 89 d6 mov %rdx,%rsi | |
583d: 48 8d 5f fe lea -0x2(%rdi),%rbx | |
5841: 48 f7 e3 mul %rbx | |
5844: 0f af de imul %esi,%ebx | |
5847: 48 0f a4 ce 3f shld $0x3f,%rcx,%rsi | |
584c: 48 8d 0c 76 lea (%rsi,%rsi,2),%rcx | |
5850: 01 da add %ebx,%edx |
5826: xor %ecx,%ecx | |
5828: cmp $0xffffffffffffffff,%rsi | |
582c: je 5840 | |
582e: lea -0x1(%rsi),%rax | |
5832: mul %rsi | |
5835: mov %rdx,%rcx | |
5838: shld $0x3f,%rax,%rcx | |
583d: add %rsi,%rcx | |
5840: ... use %rcx |
(defun jimb-rust-clean-error () | |
"Clean up an error message from rustc to fit nicely in the book. | |
Run this command with point on the first line of an error message | |
copied from rustc and pasted into a Markdown file; we'll clean it | |
up and indent it as a code block." | |
(interactive) | |
(save-excursion | |
(forward-line 0) | |
(let ((top (point))) | |
(let ((line-was-interesting t) |
fn partition<T: Ord>(a: &mut[T]) -> usize { | |
assert!(a.len() >= 2); | |
let mut pivot = 0; | |
let (mut i, mut j) = (0, a.len()); | |
loop { | |
loop { | |
j -= 1; | |
if a[j] <= a[pivot] { break; } |
mod implicit_deref { | |
use std::ops::Deref; | |
struct T(i32); | |
struct S<'a>(&'a T); | |
impl<'a> Deref for S<'a> { | |
type Target = T; | |
fn deref(&self) -> &T { &self.0; } | |
} |
use std::str::FromStr; | |
use std::fmt::Debug; | |
use std::io::stdin; | |
use std::io::stdout; | |
use std::io::Write; | |
trait Game : Clone { | |
type Move : Copy + FromStr; | |
fn start() -> Self; | |
fn moves(&self) -> Vec<Self::Move>; |