OOP in Rust
Rust
Created by KENZ / @KENZ_gelsoft
Rust
It supports a mixture of imperative procedural,
concurrent actor, object-oriented and pure
functional styles. Rust also supports generic
programming and metaprogramming, in both
static and dynamic styles.
Rust
Rust

C++
("http://ja.wikipedia.org/wiki/

"

(

)
(
(

) -) -(
( )

( )

) --

)
("http://ja.wikipedia.org/wiki/

encapsulation
(

)
1

"

)
(

)
Rust
Objective-C
C++ .h

impl
@implementation
.cpp
struct
tuple struct
enum
struct
C
src Pit{
tut on
x it
: n,
y it
:n
}
ltp=Pit{:1,y 1}
e
on x 0 : 1;
ltp:it=px
e x n
.;
tuple struct
match
src Pitit it;
tut on(n, n)
ltp=Pit1,1)
e
on(0 1;
ltp:it=mthp{Pitx _ = x}
e x n
ac
on(, ) > ;
enum
C
eu Aia {
nm nml
Dg
o,
Ct
a
}
ltmta Aia =Dg
e u : nml o;
a=Ct
a;
enum - 2
struct
tuple struct
eu Aia {
nm nml
Dg(sr f4,
o ~t, 6)
Ct{nm:~t,wih:f4}
a
ae sr egt 6
}
ltmta Aia =Dg~Cca,3.)
e u : nml o("oo" 72;
a=Ct nm:~Sot" wih:27}
a{ ae "pty, egt . ;
impl
impl
uesd:u:{qtpw;
s t:nm:sr,o}
src Pit{
tut on
x it
: n,
y it
:n
}
ip Pit{
ml on
f zr( - Pit{
n eo) > on
Pit0 0
on(, )
}
f dsac(sl,rs &on)- f2{
n itne&ef h: Pit > 3
ltd =sl. -rsx
e x efx h.;
ltd =sl. -rsy
e y efy h.;
sr(
qt
pwd a f2 23)+pwd a f2 23)
o(x s 3, f2
o(y s 3, f2
)
;
}
}

:
impl - 2
self, python
~self, &self, @self

self

f dsac(sl,rs &on)- f2{⋯ }
n itne&ef h: Pit > 3

self

static

OK
trait
trait
trait

Java

interface
trait
trait - 2
trait
tatSae{
ri hp
f da(sl,Srae;
n rw&ef ufc)
f budn_o(sl)- BudnBx
n onigbx&ef > onigo;
}
trait
impl
ip TATfrTP {..}
ml RI o YE .
src Crl {
tut ice
rdu:f4
ais 6,
cne:Pit
etr on,
}
ip SaefrCrl {
ml hp o ice
f da(sl,s Srae {d_rwcrl(,*ef;}
n rw&ef : ufc) oda_ices sl)
f budn_o(sl)- BudnBx{
n onigbx&ef > onigo
ltr=sl.ais
e
efrdu;
BudnBxx sl.etrx-r y sl.etry-r
onigo{: efcne.
, : efcne.
,
wdh 20*r hih:20*r
it: .
, egt .
}
}
}
trait
trait
trait

Rust

trait
Adhoc Polyphormism
trait Haskell Type Class
impl
(trait)
pub, priv
Rust OOP
trait
enum

impl

match
trait
Tutorial

Manual
impl
trait

mix-in
tatSae{f ae( - f4 }
ri hp
n ra) > 6;
tatCrl :Sae{f rdu( - f4 }
ri ice hp
n ais) > 6;
tatFo{
ri o
f dfutip( {/ DfutIpeetto * }
n eal_ml) * eal mlmnain /
}
trait

-2
trait(supertrait)

ltmcrl:Crl =@yicea @ice
e yice ice mcrl s Crl;
ltnnes =mcrl.ais)*mcrl.ra)
e osne yicerdu(
yiceae(;
trait
f rdu_ie_raT Crl>c T - f4{
n aistmsae<: ice(: ) > 6
/ ``i bt aCrl adaSae
/ c s oh ice n
hp
crdu( *cae(
.ais) .ra)
}

-3
enum
eu Fo{
nm o
A
,
B
}
ip Fo{
ml o
f d_ak&ef {
n ots(sl)
mth*ef{
ac sl
A= d__hn(,
> oatig)
B= d__hn(
> obtig)
}
}
}

impl

match
Rust OOP

COM
Rust OOP

-2
impl

trait impl
Generics Programming

C++
…
Java

type erasure

C#
-

wxRust
Rust
3

(*1)
*1: 2013
*2:

(*2)GUI

OOP in Rust