Follow TV Tropes

Following

History MediaNotes / Rust

Go To

OR

Is there an issue? Send a MessageReason:
None


Rust is a [[https://en.wikipedia.org/wiki/Type_system#STATIC statically-typed]], [[https://en.wikipedia.org/wiki/Programming_paradigm#Support_for_multiple_paradigms multi-paradigm]], [[https://en.wikipedia.org/wiki/Concurrent_computing concurrent]] UsefulNotes/ProgrammingLanguage with an emphasis on '''''speed''''' and '''''safety'''''. While a relatively new language, Rust has managed to be [[https://insights.stackoverflow.com/survey/2019#technology-_-most-loved-dreaded-and-wanted-languages Github's most beloved programming language since 2016]].

to:

Rust is a [[https://en.wikipedia.org/wiki/Type_system#STATIC statically-typed]], [[https://en.wikipedia.org/wiki/Programming_paradigm#Support_for_multiple_paradigms multi-paradigm]], [[https://en.wikipedia.org/wiki/Concurrent_computing concurrent]] UsefulNotes/ProgrammingLanguage MediaNotes/ProgrammingLanguage with an emphasis on '''''speed''''' and '''''safety'''''. While a relatively new language, Rust has managed to be [[https://insights.stackoverflow.com/survey/2019#technology-_-most-loved-dreaded-and-wanted-languages Github's most beloved programming language since 2016]].
Is there an issue? Send a MessageReason:
Page was movedfrom Useful Notes.Rust to Media Notes.Rust. Null edit to update page.

Added: 2606

Changed: 2480

Removed: 341

Is there an issue? Send a MessageReason:
None



[[hardline]]

[[folder:Code Examples]]

!!!Hello Rust
@@'''[[gray:fn]]''' [[gray:main]]'''[[gray:(){]]'''\\
    [[gray:println'''!(''']][[red:"Hello World!"]][[gray:''')''';]]\\
'''[[gray:}]]'''\\
@@

to:

\n[[hardline]]\n\n[[folder:Code Examples]]\n\n!!!Hello Rust\n@@'''[[gray:fn]]''' [[gray:main]]'''[[gray:(){]]'''\\\n    [[gray:println'''!(''']][[red:"Hello World!"]][[gray:''')''';]]\\\n'''[[gray:}]]'''\\\n@@!!Features Overview
These are some of features of Rust that help it stand out and what makes it increasingly popular for programmers used to C and C++. This isn't a comprehensive list however.

!!! Expression based
In Rust, any part of the function body can be considered an ''expression'', or something that returns a value. This allows for an implicit return of a value in a function by omitting the semi-colon where one would traditionally use the keyword ''return''

!!!Data ownership and lifetime
Part of how Rust achieves memory safety is enforcing a few rules regarding data ownership and lifetime. Ownership is the idea that some function owns the data. Once the function is done, if ownership was not explicitly transferred, then the data is automatically dropped from memory. Other functions can also ''borrow'' data, allowing a read-only reference to the data. However, if the ownership is transferred in the middle of a function, the function that used to own said data can no longer use it unless the new owner passes it back.

All of this is handled by the compiler by the way, meaning if the programmer doesn't keep up with this, the compiler will tell them of it.

'''Example of ownership'''
@@fn print_string(s: String) {\\
    println!("{}", s);\\
}\\



Outputs Hello World to the console using the println! macro. You must wrap your program in the 'main' function.

!!!Variable Declaration and Concatenation
@@'''[[gray:fn]]''' [[gray:main]]'''[[gray:(){]]'''\\
    [[gray:'''let''' a =]] [[teal:10]][[gray:;]]\\
    [[gray:'''let''' b =]] [[teal:7]][[gray:;]]\\
    [[gray:'''let''' c =]] [[red:"hi"]][[gray:;]]\\
    [[gray:println'''!(]]'''[[red:"{}"]][[gray:, a+b''')''';]]\\
    // Outputs 17\\
    [[gray:println'''!(''']][[red:"{}"]][[gray:, b+c''')''';]]\\
    // Throws an error\\
    [[gray:println'''!(]]'''[[red:"Hello and {}"]][[gray:, c''')''';]]\\
    // Outputs Hello and hi\\
'''[[gray:}]]'''\\

to:

Outputs Hello World to the console using the println! macro. You must wrap your program in the 'main' function.

!!!Variable Declaration and Concatenation
@@'''[[gray:fn]]''' [[gray:main]]'''[[gray:(){]]'''\\
    [[gray:'''let''' a =]] [[teal:10]][[gray:;]]\\
    [[gray:'''let''' b =]] [[teal:7]][[gray:;]]\\
    [[gray:'''let''' c =]] [[red:"hi"]][[gray:;]]\\
    [[gray:println'''!(]]'''[[red:"{}"]][[gray:, a+b''')''';]]\\
fn main() {\\
    let s = String::from("Hello, World");\\
    print_string(s); // s consumed by print_string\\
    // Outputs 17\\
    [[gray:println'''!(''']][[red:"{}"]][[gray:, b+c''')''';]]\\
s has been moved, so cannot be used any more\\
    // Throws an another print_string(s); would result in a compile error\\
    [[gray:println'''!(]]'''[[red:"Hello and {}"]][[gray:, c''')''';]]\\
    // Outputs Hello and hi\\
'''[[gray:}]]'''\\
}\\




!!!Memory Safety and Management
One standout feature of Rust is that it does not have a ''null'' value. This was done because ''null'' has wrecked havoc on a lot of other programming languages because you're not supposed to use null for anything, and using it either causes an outright error or unpredictable behavior. It's been called by its inventor [[https://www.google.com/search?q=null+the+billion+dollar+mistake The Billion Dollar Mistake]]

While not exactly a standout feature, but one that sets it apart from other languages made since the mid 90s is the lack of a garbage collector. Resources are taken through the [[https://en.wikipedia.org/wiki/Resource_acquisition_is_initialization Resource Acquisition Is Initialization (RIAA)]] principle and optionally through a reference counter. In addition, all variables have read-only access, requiring an explicit declaration of ''mut'' (for mutable) if the variable can be changed.

!!!The Rust Compiler
The tool that turns Rust code into a program, and one that's rather powerful. The compiler handles all of the memory checking, which includes making that pointers have some reference to something before being used. By more or less forcing the programmer to fix their issues up front, programs written in Rust tend to be highly reliable from the get go.

The other feature of the compiler is that it's really helpful in pointing out what the problem is in a more useful way than most compilers, especially from popular ones like gcc for C (though gcc has gotten better at reporting issues with code).

[[hardline]]

!!Code Examples
[[folder:Hello Rust]]
@@'''[[gray:fn]]''' [[gray:main]]'''[[gray:(){]]'''\\
    [[gray:println'''!(''']][[red:"Hello World!"]][[gray:''')''';]]\\
'''[[gray:}]]'''\\
@@



Rust uses the let keyword to declare variables for all data types; unusual for a low level language. Rust will not concatenate a string and a number automatically and will throw an error in the compiler.

!!!For Loops

to:

Rust uses Outputs Hello World to the let keyword to declare variables for all data types; unusual for a low level language. Rust will not concatenate a string and a number automatically and will throw an error console using the println! macro. You must wrap your program in the compiler.

!!!For Loops
'main' function.
[[/folder]]

[[folder:Variable Declaration and Concatenation]]



    [[gray:'''for''' i '''in''']] [[teal:0]]..[[teal:10]] '''[[gray:{]]'''\\
[[gray:println'''!(''']][[red:"{}"]],i'''[[gray:)]]''';\\
    '''[[gray:}]]'''\\

to:

    [[gray:'''for''' i '''in''']] [[teal:0]]..[[teal:10]] '''[[gray:{]]'''\\
[[gray:println'''!(''']][[red:"{}"]],i'''[[gray:)]]''';\\
    '''[[gray:}]]'''\\
    [[gray:'''let''' a =]] [[teal:10]][[gray:;]]\\
    [[gray:'''let''' b =]] [[teal:7]][[gray:;]]\\
    [[gray:'''let''' c =]] [[red:"hi"]][[gray:;]]\\
    [[gray:println'''!(]]'''[[red:"{}"]][[gray:, a+b''')''';]]\\
    // Outputs 17\\
    [[gray:println'''!(''']][[red:"{}"]][[gray:, b+c''')''';]]\\
    // Throws an error\\
    [[gray:println'''!(]]'''[[red:"Hello and {}"]][[gray:, c''')''';]]\\
    // Outputs Hello and hi\\



Rust’s for loops work a bit differently than in other languages. In this example, 0..10 is an expression that takes a start and an end position, and gives an iterator over those values. The upper bound is exclusive though, so the loop will print 0 through 9, not 10.

to:

Rust’s Rust uses the let keyword to declare variables for loops work all data types; unusual for a bit differently than in other languages. In this example, 0..10 is an expression that takes a start and an end position, and gives an iterator over those values. The upper bound is exclusive though, so the loop low level language. Rust will print 0 through 9, not 10.
concatenate a string and a number automatically and will throw an error in the compiler.




to:

[[folder:For Loops]]

@@'''[[gray:fn]]''' [[gray:main]]'''[[gray:(){]]'''\\
    [[gray:'''for''' i '''in''']] [[teal:0]]..[[teal:10]] '''[[gray:{]]'''\\
[[gray:println'''!(''']][[red:"{}"]],i'''[[gray:)]]''';\\
    '''[[gray:}]]'''\\
'''[[gray:}]]'''\\
@@
\\
Rust’s for loops work a bit differently than in other languages. In this example, 0..10 is an expression that takes a start and an end position, and gives an iterator over those values. The upper bound is exclusive though, so the loop will print 0 through 9, not 10.
[[/folder]]

Added: 24

Removed: 28

Is there an issue? Send a MessageReason:
None


----

[[folder:Code Examples]]


Added DiffLines:

[[folder:Code Examples]]
Is there an issue? Send a MessageReason:
None


Rust is a [[https://en.wikipedia.org/wiki/Type_system#STATIC statically-typed]], [[https://en.wikipedia.org/wiki/Programming_paradigm#Support_for_multiple_paradigms multi-paradigm]], [[https://en.wikipedia.org/wiki/Concurrent_computing concurrent]] UsefulNotes/ProgrammingLanguage with an emphasis on '''speed''' and '''safety'''. While a relatively new language, Rust has managed to be [[https://insights.stackoverflow.com/survey/2019#technology-_-most-loved-dreaded-and-wanted-languages Github's most beloved programming language since 2016]].

to:

Rust is a [[https://en.wikipedia.org/wiki/Type_system#STATIC statically-typed]], [[https://en.wikipedia.org/wiki/Programming_paradigm#Support_for_multiple_paradigms multi-paradigm]], [[https://en.wikipedia.org/wiki/Concurrent_computing concurrent]] UsefulNotes/ProgrammingLanguage with an emphasis on '''speed''' '''''speed''''' and '''safety'''.'''''safety'''''. While a relatively new language, Rust has managed to be [[https://insights.stackoverflow.com/survey/2019#technology-_-most-loved-dreaded-and-wanted-languages Github's most beloved programming language since 2016]].



Rust began as side project of Mozilla employee, Graydon Hoare. Mozilla got involved in 2009 and sponsored the language once it was mature enough to run basic tests and demonstrate its core concepts. Featuring both Mozilla and Non-Mozilla developers, Rust is developed by a diverse and global community of enthusiasts. Rustc (Rust's compiler) has over 1,000 unique contributors.

to:

Rust began as side project of Mozilla employee, Graydon Hoare. Mozilla got involved in 2009 and sponsored the language once it was mature enough to run basic tests and demonstrate its core concepts. Featuring both Mozilla and Non-Mozilla developers, Rust is developed by a diverse and global community of enthusiasts. Rustc rustc (Rust's compiler) has over 1,000 unique contributors.



Outputs Hello World to the console.

to:

Outputs Hello World to the console.
console using the println! macro. You must wrap your program in the 'main' function.



descrition

to:

descrition
Rust uses the let keyword to declare variables for all data types; unusual for a low level language. Rust will not concatenate a string and a number automatically and will throw an error in the compiler.
Is there an issue? Send a MessageReason:
None


    '''[[gray:for''' i '''in]]''' [[teal:0]]..[[teal:10]] '''[[gray:{]]'''\\

to:

    '''[[gray:for'''     [[gray:'''for''' i '''in]]''' '''in''']] [[teal:0]]..[[teal:10]] '''[[gray:{]]'''\\
Is there an issue? Send a MessageReason:
None


    '''[[gray:for]]''' i '''[[gray:in]]''' [[teal:0]]..[[teal:10]] '''[[gray:{]]'''\\

to:

    '''[[gray:for]]'''     '''[[gray:for''' i '''[[gray:in]]''' '''in]]''' [[teal:0]]..[[teal:10]] '''[[gray:{]]'''\\
Is there an issue? Send a MessageReason:
None


[[gray:println'''gray:!(''']][[red:"{}"]],i'''[[gray:)]]''';\\

to:

[[gray:println'''gray:!(''']][[red:"{}"]],i'''[[gray:)]]''';\\[[gray:println'''!(''']][[red:"{}"]],i'''[[gray:)]]''';\\
Is there an issue? Send a MessageReason:
None




to:

\nRust’s for loops work a bit differently than in other languages. In this example, 0..10 is an expression that takes a start and an end position, and gives an iterator over those values. The upper bound is exclusive though, so the loop will print 0 through 9, not 10.
Is there an issue? Send a MessageReason:
None


    [[gray:println'''!(''']][[red:"Hello World!"]]'''[[gray:)]]'''[[gray:;]]\\

to:

    [[gray:println'''!(''']][[red:"Hello World!"]]'''[[gray:)]]'''[[gray:;]]\\World!"]][[gray:''')''';]]\\



    let a = 10;\\
    let b = 7;\\
    let c = "hi";\\
    println!("{}", a+b);\\

to:

    let     [[gray:'''let''' a = 10;\\
    let
=]] [[teal:10]][[gray:;]]\\
    [[gray:'''let'''
b = 7;\\
    let
=]] [[teal:7]][[gray:;]]\\
    [[gray:'''let'''
c = "hi";\\
    println!("{}", a+b);\\
=]] [[red:"hi"]][[gray:;]]\\
    [[gray:println'''!(]]'''[[red:"{}"]][[gray:, a+b''')''';]]\\



    println!("{}", b+c);\\

to:

    println!("{}", b+c);\\    [[gray:println'''!(''']][[red:"{}"]][[gray:, b+c''')''';]]\\



    [[gray:println]]'''[[gray:!(]]'''[[red:"Hello and {}"]][[gray:, c''')''';]]\\

to:

    [[gray:println]]'''[[gray:!(]]'''[[red:"Hello     [[gray:println'''!(]]'''[[red:"Hello and {}"]][[gray:, c''')''';]]\\



println'''[[gray:!(]]'''[[red:"{}"]],i'''[[gray:)]]''';\\

to:

println'''[[gray:!(]]'''[[red:"{}"]],i'''[[gray:)]]''';\\[[gray:println'''gray:!(''']][[red:"{}"]],i'''[[gray:)]]''';\\
Is there an issue? Send a MessageReason:
None


    [[gray:println'''!(''']][[rede"Hello World!");\\

to:

    [[gray:println'''!(''']][[rede"Hello World!");\\    [[gray:println'''!(''']][[red:"Hello World!"]]'''[[gray:)]]'''[[gray:;]]\\
Is there an issue? Send a MessageReason:
None


@@fn main(){\\
    println!("Hello World!");\\
}\\

to:

@@fn main(){\\
    println!("Hello
@@'''[[gray:fn]]''' [[gray:main]]'''[[gray:(){]]'''\\
    [[gray:println'''!(''']][[rede"Hello
World!");\\
}\\'''[[gray:}]]'''\\



@@fn main(){\\
let a = 10;\\
let b = 7;\\
let c = "hi";\\
println!("{}", a+b);\\
// Outputs 17\\
println!("{}", b+c);\\
// Throws an error\\
println!("Hello and {}", c);\\
// Outputs Hello and hi\\
}\\

to:

@@fn main(){\\
let
@@'''[[gray:fn]]''' [[gray:main]]'''[[gray:(){]]'''\\
    let
a = 10;\\
let
10;\\
    let
b = 7;\\
let
7;\\
    let
c = "hi";\\
println!("{}", a+b);\\
//
"hi";\\
    println!("{}", a+b);\\
    //
Outputs 17\\
println!("{}", b+c);\\
//
17\\
    println!("{}", b+c);\\
    //
Throws an error\\
println!("Hello
error\\
    [[gray:println]]'''[[gray:!(]]'''[[red:"Hello
and {}", c);\\
//
{}"]][[gray:, c''')''';]]\\
    //
Outputs Hello and hi\\
}\\'''[[gray:}]]'''\\



@@[[gray:fn]] main[[gray:(){]]\\
[[gray:for]] i [[gray:in]] [[teal:0]]..[[teal:10]] [[gray:{]]\\
println[[gray:!(]][[red:"{}"]],i[[gray:)]];\\
[[gray:}]]\\
[[gray:}]]\\

to:

@@[[gray:fn]] main[[gray:(){]]\\
[[gray:for]]
@@'''[[gray:fn]]''' [[gray:main]]'''[[gray:(){]]'''\\
    '''[[gray:for]]'''
i [[gray:in]] '''[[gray:in]]''' [[teal:0]]..[[teal:10]] [[gray:{]]\\
println[[gray:!(]][[red:"{}"]],i[[gray:)]];\\
[[gray:}]]\\
[[gray:}]]\\
'''[[gray:{]]'''\\
println'''[[gray:!(]]'''[[red:"{}"]],i'''[[gray:)]]''';\\
    '''[[gray:}]]'''\\
'''[[gray:}]]'''\\

Added: 491

Changed: 5

Is there an issue? Send a MessageReason:
None


Rust is a [[https://en.wikipedia.org/wiki/Type_system#STATIC statically-typed]], [[https://en.wikipedia.org/wiki/Programming_paradigm#Support_for_multiple_paradigms multi-paradigm]], [[https://en.wikipedia.org/wiki/Concurrent_computing concurrent]] UsefulNotes/ProgrammingLanguage with an emphasis on '''speed''' and '''safety'''. While a relatively new language, Rust managed to be [[https://insights.stackoverflow.com/survey/2019#technology-_-most-loved-dreaded-and-wanted-languages Github's most beloved programming language since 2016]].

You can try out Rust for yourself [[https://play.rust-lang.org/ here]]


to:

Rust is a [[https://en.wikipedia.org/wiki/Type_system#STATIC statically-typed]], [[https://en.wikipedia.org/wiki/Programming_paradigm#Support_for_multiple_paradigms multi-paradigm]], [[https://en.wikipedia.org/wiki/Concurrent_computing concurrent]] UsefulNotes/ProgrammingLanguage with an emphasis on '''speed''' and '''safety'''. While a relatively new language, Rust has managed to be [[https://insights.stackoverflow.com/survey/2019#technology-_-most-loved-dreaded-and-wanted-languages Github's most beloved programming language since 2016]].

You can try out Rust for yourself [[https://play.rust-lang.org/ here]]

here]].



Added DiffLines:

!!!Hello Rust


Added DiffLines:

!!!Variable Declaration and Concatenation
@@fn main(){\\
let a = 10;\\
let b = 7;\\
let c = "hi";\\
println!("{}", a+b);\\
// Outputs 17\\
println!("{}", b+c);\\
// Throws an error\\
println!("Hello and {}", c);\\
// Outputs Hello and hi\\
}\\
@@
\\
descrition

!!!For Loops

@@[[gray:fn]] main[[gray:(){]]\\
[[gray:for]] i [[gray:in]] [[teal:0]]..[[teal:10]] [[gray:{]]\\
println[[gray:!(]][[red:"{}"]],i[[gray:)]];\\
[[gray:}]]\\
[[gray:}]]\\
@@
\\

Is there an issue? Send a MessageReason:
None

Added DiffLines:

[[quoteright:250:https://static.tvtropes.org/pmwiki/pub/images/rustthrow.jpeg]]

Rust is a [[https://en.wikipedia.org/wiki/Type_system#STATIC statically-typed]], [[https://en.wikipedia.org/wiki/Programming_paradigm#Support_for_multiple_paradigms multi-paradigm]], [[https://en.wikipedia.org/wiki/Concurrent_computing concurrent]] UsefulNotes/ProgrammingLanguage with an emphasis on '''speed''' and '''safety'''. While a relatively new language, Rust managed to be [[https://insights.stackoverflow.com/survey/2019#technology-_-most-loved-dreaded-and-wanted-languages Github's most beloved programming language since 2016]].

You can try out Rust for yourself [[https://play.rust-lang.org/ here]]


!!History

Rust began as side project of Mozilla employee, Graydon Hoare. Mozilla got involved in 2009 and sponsored the language once it was mature enough to run basic tests and demonstrate its core concepts. Featuring both Mozilla and Non-Mozilla developers, Rust is developed by a diverse and global community of enthusiasts. Rustc (Rust's compiler) has over 1,000 unique contributors.

By 2011, Rust had successfully compiled itself and was shortly after released to the public in January, 2012.


----

[[folder:Code Examples]]

[[hardline]]

@@fn main(){\\
    println!("Hello World!");\\
}\\
@@
\\
Outputs Hello World to the console.

[[/folder]]


!!Works Written in Rust
[[folder:Software]]

* Components in the ''Firefox'' browser such as [[https://blog.mozilla.org/firefox/put-trust-rust-shipping-now-firefox/ an MP4 parser for video files have been rewritten in Rust]]

[[/folder]]

----

Top