Telegram Group & Telegram Channel
🔍 Вопрос: что выведет этот код на Rust?

fn main() {
let mut v = vec![1, 2, 3];
let first = &v[0];

v.push(4);

println!("First: {}", first);
}

---
✔️ Правильный ответ: Ошибка компиляции
---
🧠 Разбор:
- let first = &v[0];иммутабельная ссылка
- v.push(4);мутабельная операция

Rust запрещает это: нельзя иметь и иммутабельную ссылку, и мутабельную операцию одновременно!

📚 Rust выдаст ошибку компиляции:
error[E0502]: cannot borrow v as mutable because it is also borrowed as immutable

💥 Подвох: в C++, Go или JS это бы сработало.

Rust завернет такое на стадии компиляции

@rust_code



tg-me.com/rust_code/925
Create:
Last Update:

🔍 Вопрос: что выведет этот код на Rust?


fn main() {
let mut v = vec![1, 2, 3];
let first = &v[0];

v.push(4);

println!("First: {}", first);
}

---
✔️ Правильный ответ: Ошибка компиляции
---
🧠 Разбор:
- let first = &v[0];иммутабельная ссылка
- v.push(4);мутабельная операция

Rust запрещает это: нельзя иметь и иммутабельную ссылку, и мутабельную операцию одновременно!

📚 Rust выдаст ошибку компиляции:
error[E0502]: cannot borrow v as mutable because it is also borrowed as immutable

💥 Подвох: в C++, Go или JS это бы сработало.

Rust завернет такое на стадии компиляции

@rust_code

BY Rust


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/rust_code/925

View MORE
Open in Telegram


Rust Telegram | DID YOU KNOW?

Date: |

At a time when the Indian stock market is peaking and has rallied immensely compared to global markets, there are companies that have not performed in the last 10 years. These are definitely a minor portion of the market considering there are hundreds of stocks that have turned multibagger since 2020. What went wrong with these stocks? Reasons vary from corporate governance, sectoral weakness, company specific and so on. But the more important question is, are these stocks worth buying?

Launched in 2013, Telegram allows users to broadcast messages to a following via “channels”, or create public and private groups that are simple for others to access. Users can also send and receive large data files, including text and zip files, directly via the app.The platform said it has more than 500m active users, and topped 1bn downloads in August, according to data from SensorTower.Rust from in


Telegram Rust
FROM USA