Rust (bahasa pengaturcaraan): Perbezaan antara semakan

Daripada Wikipedia, ensiklopedia bebas.
Kandungan dihapus Kandungan ditambah
Kurniasan (bincang | sumb.)
Letak infobox
Kurniasan (bincang | sumb.)
→‎Contoh: import contoh dari en.wiki
 
Baris 28: Baris 28:


== Contoh ==
== Contoh ==
=== Indahnya dunia ===
<syntaxhighlight lang="rust">
<syntaxhighlight lang="rust">
fn main() {
fn main() {
println!("Indahnya Dunia!");
println!("Indahnya Dunia!");
}
</syntaxhighlight>

=== Fungsi faktorial ===
==== Rekursif ====
<syntaxhighlight lang="rust">
fn factorial(i: u64) -> u64 {
match i {
0 => 1,
n => n * factorial(n-1)
}
}
</syntaxhighlight>

==== Iteratif ====
<syntaxhighlight lang="rust">
fn factorial(i: u64) -> u64 {
let mut acc = 1;
for num in 2..=i {
acc *= num;
}
acc
}
}
</syntaxhighlight>
</syntaxhighlight>

Semakan semasa pada 12:47, 29 November 2019

Rust
Muncul pada7 Julai 2010; 13 tahun yang lalu (2010-07-07)
Direka olehGraydon Hoare
PembangunThe Rust Project
Lepasan stabil1.39.0[1] (7 November 2019; 4 tahun yang lalu (2019-11-07))
Disiplin penjenisanDiinferens, linear, nominal, statik, kuat
DipengaruhiAlef,[2] C#,[2] C++,[2] Cyclone,[2][3] Erlang,[2] Haskell,[2] Limbo,[2] Newsqueak,[2] OCaml,[2] Ruby,[2] Scheme,[2] Standard ML,[2] Swift[2][4]
MempengaruhiCrystal, Elm,[5] Idris,[6] Spark,[7] Swift[8]
PelantarARM, IA-32, x86-64, MIPS, PowerPC, SPARC, RISC-V[9][10]
OSLinux, macOS, Windows, FreeBSD, OpenBSD,[11] Redox, Android, iOS[12]
LesenMIT atau Apache 2.0[13]
Sambugan fail biasa.rs, .rlib
Laman webwww.rust-lang.org

Rust ialah sebuah bahasa pengaturcaraan yang dibangunkan oleh Mozilla. Berbeza dengan bahasa pengaturcaraan moden lain, ia tidak menggunakan sebarang pengutip sampah automatik, sebaliknya ia menggunakan konsep pemerolehan sumber adalah pengawalan (RAII).

Contoh[sunting | sunting sumber]

Indahnya dunia[sunting | sunting sumber]

fn main() {
    println!("Indahnya Dunia!");
}

Fungsi faktorial[sunting | sunting sumber]

Rekursif[sunting | sunting sumber]

fn factorial(i: u64) -> u64 {
    match i {
        0 => 1,
        n => n * factorial(n-1)
    }
}

Iteratif[sunting | sunting sumber]

fn factorial(i: u64) -> u64 {
    let mut acc = 1;
    for num in 2..=i {
        acc *= num;
    }
    acc
}

Rujukan[sunting | sunting sumber]

  1. ^ The Rust Release Team (7 November 2019). "Announcing Rust 1.39.0". The Rust Programming Language Blog. Dicapai pada 7 November 2019.
  2. ^ a b c d e f g h i j k l m "The Rust Reference: Appendix: Influences". Dicapai pada November 11, 2018. Rust is not a particularly original language, with design elements coming from a wide range of sources. Some of these are listed below (including elements that have since been removed): SML, OCaml [...] C++ [...] ML Kit, Cyclone [...] Haskell [...] Newsqueak, Alef, Limbo [...] Erlang [...] Ruby [...] Swift [...] Scheme [...] C# [...]
  3. ^ "Note Research: Type System". 2015-02-01. Dicapai pada 2015-03-25. Papers that have had more or less influence on Rust, or which one might want to consult for inspiration or to understand Rust's background. [...] Region based memory management in Cyclone [...] Safe memory management in Cyclone
  4. ^ "RFC for 'if let' expression". Dicapai pada December 4, 2014.
  5. ^ "Command Optimizations?". 2014-06-26. Dicapai pada 2014-12-10. I just added the outline of a Result library that lets you use richer error messages. It's like Either except the names are more helpful. The names are inspired by Rust's Result library.
  6. ^ "Idris – Uniqueness Types". Dicapai pada 2018-11-20.
  7. ^ Jaloyan, Georges-Axel (19 October 2017). "Safe Pointers in SPARK 2014". Dicapai pada 1 January 2019. Cite journal requires |journal= (bantuan)
  8. ^ Lattner, Chris. "Chris Lattner's Homepage". Nondot.org. Dicapai pada 2019-05-14.
  9. ^ "Rust Platform Support". Rust Forge. Dicapai pada 2019-05-19.
  10. ^ "Frequently Asked Questions". Rust Embedded. Dicapai pada 2019-05-14.
  11. ^ "OpenBSD ports". Dicapai pada 2018-04-03.
  12. ^ "Building and Deploying a Rust library on iOS". 6 September 2017. Dicapai pada 11 January 2019.

Pautan luar[sunting | sunting sumber]