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
| struct A {n: uint} | |
| impl A: cmp::Eq { | |
| pure fn eq(other: &A) -> bool { | |
| self.n == other.n | |
| } | |
| pure fn ne(other: &A) -> bool { | |
| !self.eq(other) | |
| } | |
| } |
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
| I'm announcing an initial version of an API search tool for Rust. It is inspired by the api search tool for haskell | |
| called Hoogle (http://www.haskell.org/hoogle). It is very new (I started working on it a week ago), so it has a long | |
| way to go, but for a taste of the kind of things it can currently do: | |
| rustle> str -> uint | |
| core::str::capacity - fn capacity(s: & const ~str) -> uint - Returns the number of single-byte characters the | |
| string can hold without reallocating | |
| core::str::char_len - fn char_len(s: & str) -> uint - Returns the number of characters that a string holds | |
| core::str::len - fn len(s: & str) -> uint - Returns the string length/size in bytes not counting the null terminator | |
| … |
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
| struct C {mut d: ~[uint]} | |
| fn main() { | |
| let mut c = C {d: ~[1,2,3]}; | |
| f(&c); | |
| } | |
| fn f(x: &C) { | |
| for x.d.each |e| { | |
| io::println(~"a"); |
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
| fn main() { | |
| let x = (~"a",~"b"); | |
| io::println(x.second()); | |
| } |
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
| extern mod std; // for tests | |
| use reflect::*; | |
| enum fmt_visitor = @{ | |
| out: io::WriterUtil, | |
| }; | |
| // duplicated from syntax/ast.rs so as not to depend on it | |
| enum mutability { m_mutbl, m_imm, m_const, } | |
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
| import intrinsic::{tydesc, get_tydesc, visit_tydesc, ty_visitor}; | |
| import libc::c_void; | |
| trait MovablePtr { | |
| fn move_ptr(adjustment: fn(*c_void) -> *c_void); | |
| } | |
| // FIXME #3262: this is a near-duplicate of code in core::vec. | |
| type VecRepr = { | |
| box_header: (uint, uint, uint, uint), |
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
| fn visit_estr_fixed(_n: uint, _sz: uint, | |
| _align: uint) -> bool { | |
| self.align(_align); | |
| self.out += ~"\""; | |
| unsafe { | |
| self.out += str::unsafe::from_buf_len(self.ptr as *u8, _n); | |
| } | |
| self.bump(_sz); | |
| self.out += ~"\""; | |
| true |
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
| fn visit_evec_uniq(_mtbl: uint, _inner: *tydesc) -> bool { | |
| self.out += ~"~["; | |
| self.align_to::<~[u8]>(); | |
| self.visit_unboxed_vec(_mtbl, _inner); | |
| self.bump_past::<~[u8]>(); | |
| self.out += ~"]"; | |
| true | |
| } | |
| fn visit_unboxed_vec(_mtbl: uint, _inner: *tydesc) -> bool { |
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
| ... | |
| fn visit_enter_enum_variant(_variant: uint, | |
| _disr_val: int, | |
| _n_fields: uint, | |
| _name: &str) -> bool { | |
| do self.get::<int>() |e| { | |
| if e == _disr_val { | |
| self.out += _name; | |
| } | |
| }; |
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
| macro_rules! num_visitor( | |
| ($typ:ident) => ( | |
| fn visit_$typ() -> bool { | |
| self.align_to::<$typ>(); | |
| do self.get::<$typ>() |i| { | |
| self.out += $typ::to_str(i, 10u); | |
| }; | |
| self.bump_past::<$typ>(); | |
| true | |
| } |