AtCoder with Rust RustCoder ―― Introduction to Competitive Programming with AtCoder and Rust
- Rust’s Functional Programming Language-like features
- Is it something like
let x = if ~~~
? - The default is immutable, and even if it’s mutable, there are various constraints
- It aims to be close to Referential Transparency…?
- Is it something like
- Interesting (blu3mo)
Rust Tour - Let’s go on an adventure!
-
As a starting point
-
let
cannot be changed unless it’smut
- But can it be redeclared?
-
usize
,isize
- The index of an array is
usize
- The index of an array is
-
There are arrays and slices, right?
- Whether they are fixed-length or not
- Arrays are like a version of tuples with n elements
-
If, match, functions, and blocks without
;
at the end are used as return values. This is the best way to create concise logic that returns a value, which can be assigned to a new variable. -
Rust’s Error
do_something_that_might_fail(432)?
- If an Error is returned, it becomes
return Err(e)
- If an Error is returned, it becomes
- If
do_something_that_might_fail(432)
is executed inmain()
,main
will return with an error and exit
-
Vec
- Similar to C++‘s vector
- The vector struct holds a reference to Heap Memory
-
Macro
println!
andvec!
are macros, right?
-
Lifetimes
- I understand that it refers to the period from creation to dropping
- However, I can’t quite grasp lifetime specifiers
- I thought lifetimes were determined by the content of the program, but can they be set artificially? Is it okay to have contradictions?
- The static lifetime, like static variables, lasts until the end of the program
- Does it mean it is placed in Data Memory?
-
Impressions
- I quite like it
- It feels clean
- It seems to aim to do things with fewer essential elements, which is beautiful (?)
- The constraints around ownership and writing asynchronous code seem difficult
- I quite like it
-
Steps to Set Up a Local Rust Development Environment on macOS 2022 - Qiita