Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -0,0 +1,5 @@
|
|||
(Long/toHexString 15) ; use forward slash for static methods
|
||||
(System/currentTimeMillis)
|
||||
|
||||
(.equals 1 2) ; use dot operator to call instance methods
|
||||
(. 1 (equals 2)) ; alternative style
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
# Static
|
||||
Method( obj, other, arg );
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
# Instance
|
||||
Method( obj, other, arg );
|
||||
26
Task/Call-an-object-method/Rust/call-an-object-method.rust
Normal file
26
Task/Call-an-object-method/Rust/call-an-object-method.rust
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
struct Foo;
|
||||
|
||||
impl Foo {
|
||||
// implementation of an instance method for struct Foo
|
||||
// returning the answer to life
|
||||
fn get_the_answer_to_life(&self) -> i32 {
|
||||
42
|
||||
}
|
||||
|
||||
// implementation of a static method for struct Foo
|
||||
// returning a new instance object
|
||||
fn new() -> Foo {
|
||||
println!("Hello, world!");
|
||||
Foo // returning the new Foo object
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// create the instance object foo,
|
||||
// by calling the static method new of struct Foo
|
||||
let foo = Foo::new();
|
||||
|
||||
// get the answer to life
|
||||
// by calling the instance method of object foo
|
||||
println!("The answer to life is {}.", foo.get_the_answer_to_life());
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue