libcore: Fix obsolete syntax in extfmt
This commit is contained in:
parent
e2fde83ce4
commit
28efc234f4
20
doc/rust.md
20
doc/rust.md
@ -206,7 +206,7 @@ The keywords are the following strings:
|
|||||||
~~~~~~~~ {.keyword}
|
~~~~~~~~ {.keyword}
|
||||||
as
|
as
|
||||||
break
|
break
|
||||||
const copy
|
copy
|
||||||
do drop
|
do drop
|
||||||
else enum extern
|
else enum extern
|
||||||
false fn for
|
false fn for
|
||||||
@ -1099,7 +1099,7 @@ const_item : "const" ident ':' type '=' expr ';' ;
|
|||||||
|
|
||||||
A *constant* is a named value stored in read-only memory in a crate.
|
A *constant* is a named value stored in read-only memory in a crate.
|
||||||
The value bound to a constant is evaluated at compile time.
|
The value bound to a constant is evaluated at compile time.
|
||||||
Constants are declared with the `const` keyword.
|
Constants are declared with the `static` keyword.
|
||||||
A constant item must have an expression giving its definition.
|
A constant item must have an expression giving its definition.
|
||||||
The definition expression of a constant is limited to expression forms that can be evaluated at compile time.
|
The definition expression of a constant is limited to expression forms that can be evaluated at compile time.
|
||||||
|
|
||||||
@ -1108,18 +1108,18 @@ The derived types are borrowed pointers, static arrays, tuples, and structs.
|
|||||||
Borrowed pointers must be have the `'static` lifetime.
|
Borrowed pointers must be have the `'static` lifetime.
|
||||||
|
|
||||||
~~~~
|
~~~~
|
||||||
const bit1: uint = 1 << 0;
|
static bit1: uint = 1 << 0;
|
||||||
const bit2: uint = 1 << 1;
|
static bit2: uint = 1 << 1;
|
||||||
|
|
||||||
const bits: [uint * 2] = [bit1, bit2];
|
static bits: [uint, ..2] = [bit1, bit2];
|
||||||
const string: &'static str = "bitstring";
|
static string: &'static str = "bitstring";
|
||||||
|
|
||||||
struct BitsNStrings {
|
struct BitsNStrings {
|
||||||
mybits: [uint *2],
|
mybits: [uint, ..2],
|
||||||
mystring: &'self str
|
mystring: &'self str
|
||||||
}
|
}
|
||||||
|
|
||||||
const bits_n_strings: BitsNStrings<'static> = BitsNStrings {
|
static bits_n_strings: BitsNStrings<'static> = BitsNStrings {
|
||||||
mybits: bits,
|
mybits: bits,
|
||||||
mystring: string
|
mystring: string
|
||||||
};
|
};
|
||||||
@ -1206,10 +1206,10 @@ For example:
|
|||||||
|
|
||||||
~~~~
|
~~~~
|
||||||
trait Num {
|
trait Num {
|
||||||
static fn from_int(n: int) -> Self;
|
fn from_int(n: int) -> Self;
|
||||||
}
|
}
|
||||||
impl Num for float {
|
impl Num for float {
|
||||||
static fn from_int(n: int) -> float { n as float }
|
fn from_int(n: int) -> float { n as float }
|
||||||
}
|
}
|
||||||
let x: float = Num::from_int(42);
|
let x: float = Num::from_int(42);
|
||||||
~~~~
|
~~~~
|
||||||
|
@ -394,7 +394,7 @@ copying.
|
|||||||
# Circle(Point, float), // origin, radius
|
# Circle(Point, float), // origin, radius
|
||||||
# Rectangle(Point, Size) // upper-left, dimensions
|
# Rectangle(Point, Size) // upper-left, dimensions
|
||||||
# }
|
# }
|
||||||
# const tau: float = 6.28f;
|
# static tau: float = 6.28f;
|
||||||
fn compute_area(shape: &Shape) -> float {
|
fn compute_area(shape: &Shape) -> float {
|
||||||
match *shape {
|
match *shape {
|
||||||
Circle(_, radius) => 0.5 * tau * radius * radius,
|
Circle(_, radius) => 0.5 * tau * radius * radius,
|
||||||
|
@ -237,7 +237,7 @@ can specify a variable's type by following it with a colon, then the type
|
|||||||
name. Constants, on the other hand, always require a type annotation.
|
name. Constants, on the other hand, always require a type annotation.
|
||||||
|
|
||||||
~~~~
|
~~~~
|
||||||
const monster_factor: float = 57.8;
|
static monster_factor: float = 57.8;
|
||||||
let monster_size = monster_factor * 10.0;
|
let monster_size = monster_factor * 10.0;
|
||||||
let monster_size: int = 50;
|
let monster_size: int = 50;
|
||||||
~~~~
|
~~~~
|
||||||
@ -916,7 +916,7 @@ use core::libc::types::os::arch::c95::size_t;
|
|||||||
struct Blob { priv ptr: *c_void }
|
struct Blob { priv ptr: *c_void }
|
||||||
|
|
||||||
impl Blob {
|
impl Blob {
|
||||||
static fn new() -> Blob {
|
fn new() -> Blob {
|
||||||
unsafe { Blob{ptr: calloc(1, int::bytes as size_t)} }
|
unsafe { Blob{ptr: calloc(1, int::bytes as size_t)} }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1222,7 +1222,7 @@ pointers to vectors are also called 'slices'.
|
|||||||
# Black, BlizzardBlue, Blue
|
# Black, BlizzardBlue, Blue
|
||||||
# }
|
# }
|
||||||
// A fixed-size stack vector
|
// A fixed-size stack vector
|
||||||
let stack_crayons: [Crayon * 3] = [Almond, AntiqueBrass, Apricot];
|
let stack_crayons: [Crayon, ..3] = [Almond, AntiqueBrass, Apricot];
|
||||||
|
|
||||||
// A borrowed pointer to stack-allocated vector
|
// A borrowed pointer to stack-allocated vector
|
||||||
let stack_crayons: &[Crayon] = &[Aquamarine, Asparagus, AtomicTangerine];
|
let stack_crayons: &[Crayon] = &[Aquamarine, Asparagus, AtomicTangerine];
|
||||||
@ -1264,7 +1264,7 @@ Square brackets denote indexing into a vector:
|
|||||||
# Aquamarine, Asparagus, AtomicTangerine,
|
# Aquamarine, Asparagus, AtomicTangerine,
|
||||||
# BananaMania, Beaver, Bittersweet };
|
# BananaMania, Beaver, Bittersweet };
|
||||||
# fn draw_scene(c: Crayon) { }
|
# fn draw_scene(c: Crayon) { }
|
||||||
let crayons: [Crayon * 3] = [BananaMania, Beaver, Bittersweet];
|
let crayons: [Crayon, ..3] = [BananaMania, Beaver, Bittersweet];
|
||||||
match crayons[0] {
|
match crayons[0] {
|
||||||
Bittersweet => draw_scene(crayons[0]),
|
Bittersweet => draw_scene(crayons[0]),
|
||||||
_ => ()
|
_ => ()
|
||||||
@ -1274,7 +1274,7 @@ match crayons[0] {
|
|||||||
A vector can be destructured using pattern matching:
|
A vector can be destructured using pattern matching:
|
||||||
|
|
||||||
~~~~
|
~~~~
|
||||||
let numbers: [int * 3] = [1, 2, 3];
|
let numbers: [int, ..3] = [1, 2, 3];
|
||||||
let score = match numbers {
|
let score = match numbers {
|
||||||
[] => 0,
|
[] => 0,
|
||||||
[a] => a * 10,
|
[a] => a * 10,
|
||||||
@ -1768,32 +1768,25 @@ s.draw_borrowed();
|
|||||||
(&@~s).draw_borrowed();
|
(&@~s).draw_borrowed();
|
||||||
~~~
|
~~~
|
||||||
|
|
||||||
Implementations may also define _static_ methods,
|
Implementations may also define standalone (sometimes called "static")
|
||||||
which don't have an explicit `self` argument.
|
methods. The absence of a `self` paramater distinguishes such methods.
|
||||||
The `static` keyword distinguishes static methods from methods that have a `self`:
|
These methods are the preferred way to define constructor functions.
|
||||||
|
|
||||||
~~~~ {.xfail-test}
|
~~~~ {.xfail-test}
|
||||||
impl Circle {
|
impl Circle {
|
||||||
fn area(&self) -> float { ... }
|
fn area(&self) -> float { ... }
|
||||||
static fn new(area: float) -> Circle { ... }
|
fn new(area: float) -> Circle { ... }
|
||||||
}
|
}
|
||||||
~~~~
|
~~~~
|
||||||
|
|
||||||
> ***Note***: In the future the `static` keyword will be removed and static methods
|
To call such a method, just prefix it with the type name and a double colon:
|
||||||
> will be distinguished solely by the presence or absence of the `self` argument.
|
|
||||||
> In the current langugage instance methods may also be declared without an explicit
|
|
||||||
> `self` argument, in which case `self` is an implicit reference.
|
|
||||||
> That form of method is deprecated.
|
|
||||||
|
|
||||||
Constructors are one common application for static methods, as in `new` above.
|
|
||||||
To call a static method, you have to prefix it with the type name and a double colon:
|
|
||||||
|
|
||||||
~~~~
|
~~~~
|
||||||
# use core::float::consts::pi;
|
# use core::float::consts::pi;
|
||||||
# use core::float::sqrt;
|
# use core::float::sqrt;
|
||||||
struct Circle { radius: float }
|
struct Circle { radius: float }
|
||||||
impl Circle {
|
impl Circle {
|
||||||
static fn new(area: float) -> Circle { Circle { radius: sqrt(area / pi) } }
|
fn new(area: float) -> Circle { Circle { radius: sqrt(area / pi) } }
|
||||||
}
|
}
|
||||||
let c = Circle::new(42.5);
|
let c = Circle::new(42.5);
|
||||||
~~~~
|
~~~~
|
||||||
@ -2055,22 +2048,23 @@ second parameter of type `self`.
|
|||||||
In contrast, in the `impl`, `equals` takes a second parameter of
|
In contrast, in the `impl`, `equals` takes a second parameter of
|
||||||
type `int`, only using `self` as the name of the receiver.
|
type `int`, only using `self` as the name of the receiver.
|
||||||
|
|
||||||
Traits can also define static methods which are called by prefixing
|
Just as in type implementations, traits can define standalone (static)
|
||||||
the method name with the trait name.
|
methods. These methods are called by prefixing the method name with the trait
|
||||||
The compiler will use type inference to decide which implementation to call.
|
name and a double colon. The compiler uses type inference to decide which
|
||||||
|
implementation to use.
|
||||||
|
|
||||||
~~~~
|
~~~~
|
||||||
trait Shape { static fn new(area: float) -> Self; }
|
trait Shape { fn new(area: float) -> Self; }
|
||||||
# use core::float::consts::pi;
|
# use core::float::consts::pi;
|
||||||
# use core::float::sqrt;
|
# use core::float::sqrt;
|
||||||
struct Circle { radius: float }
|
struct Circle { radius: float }
|
||||||
struct Square { length: float }
|
struct Square { length: float }
|
||||||
|
|
||||||
impl Shape for Circle {
|
impl Shape for Circle {
|
||||||
static fn new(area: float) -> Circle { Circle { radius: sqrt(area / pi) } }
|
fn new(area: float) -> Circle { Circle { radius: sqrt(area / pi) } }
|
||||||
}
|
}
|
||||||
impl Shape for Square {
|
impl Shape for Square {
|
||||||
static fn new(area: float) -> Square { Square { length: sqrt(area) } }
|
fn new(area: float) -> Square { Square { length: sqrt(area) } }
|
||||||
}
|
}
|
||||||
|
|
||||||
let area = 42.5;
|
let area = 42.5;
|
||||||
@ -2312,7 +2306,7 @@ them. The `pub` keyword modifies an item's visibility, making it
|
|||||||
visible outside its containing module. An expression with `::`, like
|
visible outside its containing module. An expression with `::`, like
|
||||||
`farm::chicken`, can name an item outside of its containing
|
`farm::chicken`, can name an item outside of its containing
|
||||||
module. Items, such as those declared with `fn`, `struct`, `enum`,
|
module. Items, such as those declared with `fn`, `struct`, `enum`,
|
||||||
`type`, or `const`, are module-private by default.
|
`type`, or `static`, are module-private by default.
|
||||||
|
|
||||||
Visibility restrictions in Rust exist only at module boundaries. This
|
Visibility restrictions in Rust exist only at module boundaries. This
|
||||||
is quite different from most object-oriented languages that also
|
is quite different from most object-oriented languages that also
|
||||||
|
@ -81,7 +81,7 @@ fn run_rfail_test(config: config, props: TestProps, testfile: &Path) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// The value our Makefile configures valgrind to return on failure
|
// The value our Makefile configures valgrind to return on failure
|
||||||
const valgrind_err: int = 100;
|
static valgrind_err: int = 100;
|
||||||
if ProcRes.status == valgrind_err {
|
if ProcRes.status == valgrind_err {
|
||||||
fatal_ProcRes(~"run-fail test isn't valgrind-clean!", ProcRes);
|
fatal_ProcRes(~"run-fail test isn't valgrind-clean!", ProcRes);
|
||||||
}
|
}
|
||||||
@ -92,7 +92,7 @@ fn run_rfail_test(config: config, props: TestProps, testfile: &Path) {
|
|||||||
|
|
||||||
fn check_correct_failure_status(ProcRes: ProcRes) {
|
fn check_correct_failure_status(ProcRes: ProcRes) {
|
||||||
// The value the rust runtime returns on failure
|
// The value the rust runtime returns on failure
|
||||||
const rust_err: int = 101;
|
static rust_err: int = 101;
|
||||||
if ProcRes.status != rust_err {
|
if ProcRes.status != rust_err {
|
||||||
fatal_ProcRes(
|
fatal_ProcRes(
|
||||||
fmt!("failure produced the wrong error code: %d",
|
fmt!("failure produced the wrong error code: %d",
|
||||||
|
@ -483,12 +483,12 @@ pub mod rt {
|
|||||||
use vec;
|
use vec;
|
||||||
use option::{Some, None, Option};
|
use option::{Some, None, Option};
|
||||||
|
|
||||||
pub const flag_none : u32 = 0u32;
|
pub static flag_none : u32 = 0u32;
|
||||||
pub const flag_left_justify : u32 = 0b00000000000001u32;
|
pub static flag_left_justify : u32 = 0b00000000000001u32;
|
||||||
pub const flag_left_zero_pad : u32 = 0b00000000000010u32;
|
pub static flag_left_zero_pad : u32 = 0b00000000000010u32;
|
||||||
pub const flag_space_for_sign : u32 = 0b00000000000100u32;
|
pub static flag_space_for_sign : u32 = 0b00000000000100u32;
|
||||||
pub const flag_sign_always : u32 = 0b00000000001000u32;
|
pub static flag_sign_always : u32 = 0b00000000001000u32;
|
||||||
pub const flag_alternate : u32 = 0b00000000010000u32;
|
pub static flag_alternate : u32 = 0b00000000010000u32;
|
||||||
|
|
||||||
pub enum Count { CountIs(uint), CountImplied, }
|
pub enum Count { CountIs(uint), CountImplied, }
|
||||||
|
|
||||||
@ -501,7 +501,7 @@ pub mod rt {
|
|||||||
ty: Ty,
|
ty: Ty,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub pure fn conv_int(cv: Conv, i: int, buf: &mut ~str) {
|
pub fn conv_int(cv: Conv, i: int, buf: &mut ~str) {
|
||||||
let radix = 10;
|
let radix = 10;
|
||||||
let prec = get_int_precision(cv);
|
let prec = get_int_precision(cv);
|
||||||
let mut s : ~str = uint_to_str_prec(int::abs(i) as uint, radix, prec);
|
let mut s : ~str = uint_to_str_prec(int::abs(i) as uint, radix, prec);
|
||||||
@ -517,7 +517,7 @@ pub mod rt {
|
|||||||
} else { Some('-') };
|
} else { Some('-') };
|
||||||
unsafe { pad(cv, s, head, PadSigned, buf) };
|
unsafe { pad(cv, s, head, PadSigned, buf) };
|
||||||
}
|
}
|
||||||
pub pure fn conv_uint(cv: Conv, u: uint, buf: &mut ~str) {
|
pub fn conv_uint(cv: Conv, u: uint, buf: &mut ~str) {
|
||||||
let prec = get_int_precision(cv);
|
let prec = get_int_precision(cv);
|
||||||
let mut rs =
|
let mut rs =
|
||||||
match cv.ty {
|
match cv.ty {
|
||||||
@ -529,16 +529,16 @@ pub mod rt {
|
|||||||
};
|
};
|
||||||
unsafe { pad(cv, rs, None, PadUnsigned, buf) };
|
unsafe { pad(cv, rs, None, PadUnsigned, buf) };
|
||||||
}
|
}
|
||||||
pub pure fn conv_bool(cv: Conv, b: bool, buf: &mut ~str) {
|
pub fn conv_bool(cv: Conv, b: bool, buf: &mut ~str) {
|
||||||
let s = if b { "true" } else { "false" };
|
let s = if b { "true" } else { "false" };
|
||||||
// run the boolean conversion through the string conversion logic,
|
// run the boolean conversion through the string conversion logic,
|
||||||
// giving it the same rules for precision, etc.
|
// giving it the same rules for precision, etc.
|
||||||
conv_str(cv, s, buf);
|
conv_str(cv, s, buf);
|
||||||
}
|
}
|
||||||
pub pure fn conv_char(cv: Conv, c: char, buf: &mut ~str) {
|
pub fn conv_char(cv: Conv, c: char, buf: &mut ~str) {
|
||||||
unsafe { pad(cv, "", Some(c), PadNozero, buf) };
|
unsafe { pad(cv, "", Some(c), PadNozero, buf) };
|
||||||
}
|
}
|
||||||
pub pure fn conv_str(cv: Conv, s: &str, buf: &mut ~str) {
|
pub fn conv_str(cv: Conv, s: &str, buf: &mut ~str) {
|
||||||
// For strings, precision is the maximum characters
|
// For strings, precision is the maximum characters
|
||||||
// displayed
|
// displayed
|
||||||
let mut unpadded = match cv.precision {
|
let mut unpadded = match cv.precision {
|
||||||
@ -551,7 +551,7 @@ pub mod rt {
|
|||||||
};
|
};
|
||||||
unsafe { pad(cv, unpadded, None, PadNozero, buf) };
|
unsafe { pad(cv, unpadded, None, PadNozero, buf) };
|
||||||
}
|
}
|
||||||
pub pure fn conv_float(cv: Conv, f: float, buf: &mut ~str) {
|
pub fn conv_float(cv: Conv, f: float, buf: &mut ~str) {
|
||||||
let (to_str, digits) = match cv.precision {
|
let (to_str, digits) = match cv.precision {
|
||||||
CountIs(c) => (float::to_str_exact, c as uint),
|
CountIs(c) => (float::to_str_exact, c as uint),
|
||||||
CountImplied => (float::to_str_digits, 6u)
|
CountImplied => (float::to_str_digits, 6u)
|
||||||
@ -568,7 +568,7 @@ pub mod rt {
|
|||||||
} else { None };
|
} else { None };
|
||||||
unsafe { pad(cv, s, head, PadFloat, buf) };
|
unsafe { pad(cv, s, head, PadFloat, buf) };
|
||||||
}
|
}
|
||||||
pub pure fn conv_poly<T>(cv: Conv, v: &T, buf: &mut ~str) {
|
pub fn conv_poly<T>(cv: Conv, v: &T, buf: &mut ~str) {
|
||||||
let s = sys::log_str(v);
|
let s = sys::log_str(v);
|
||||||
conv_str(cv, s, buf);
|
conv_str(cv, s, buf);
|
||||||
}
|
}
|
||||||
@ -576,8 +576,7 @@ pub mod rt {
|
|||||||
// Convert a uint to string with a minimum number of digits. If precision
|
// Convert a uint to string with a minimum number of digits. If precision
|
||||||
// is 0 and num is 0 then the result is the empty string. Could move this
|
// is 0 and num is 0 then the result is the empty string. Could move this
|
||||||
// to uint: but it doesn't seem all that useful.
|
// to uint: but it doesn't seem all that useful.
|
||||||
pub pure fn uint_to_str_prec(num: uint, radix: uint,
|
pub fn uint_to_str_prec(num: uint, radix: uint, prec: uint) -> ~str {
|
||||||
prec: uint) -> ~str {
|
|
||||||
return if prec == 0u && num == 0u {
|
return if prec == 0u && num == 0u {
|
||||||
~""
|
~""
|
||||||
} else {
|
} else {
|
||||||
@ -590,7 +589,7 @@ pub mod rt {
|
|||||||
} else { s }
|
} else { s }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
pub pure fn get_int_precision(cv: Conv) -> uint {
|
pub fn get_int_precision(cv: Conv) -> uint {
|
||||||
return match cv.precision {
|
return match cv.precision {
|
||||||
CountIs(c) => c as uint,
|
CountIs(c) => c as uint,
|
||||||
CountImplied => 1u
|
CountImplied => 1u
|
||||||
@ -637,7 +636,7 @@ pub mod rt {
|
|||||||
PadFloat => (true, true),
|
PadFloat => (true, true),
|
||||||
PadUnsigned => (true, false)
|
PadUnsigned => (true, false)
|
||||||
};
|
};
|
||||||
pure fn have_precision(cv: Conv) -> bool {
|
fn have_precision(cv: Conv) -> bool {
|
||||||
return match cv.precision { CountImplied => false, _ => true };
|
return match cv.precision { CountImplied => false, _ => true };
|
||||||
}
|
}
|
||||||
let zero_padding = {
|
let zero_padding = {
|
||||||
@ -672,7 +671,7 @@ pub mod rt {
|
|||||||
buf.push_str(s);
|
buf.push_str(s);
|
||||||
}
|
}
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn have_flag(flags: u32, f: u32) -> bool {
|
pub fn have_flag(flags: u32, f: u32) -> bool {
|
||||||
flags & f != 0
|
flags & f != 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user