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: |

Telegram has exploded as a hub for cybercriminals looking to buy, sell and share stolen data and hacking tools, new research shows, as the messaging app emerges as an alternative to the dark web.An investigation by cyber intelligence group Cyberint, together with the Financial Times, found a ballooning network of hackers sharing data leaks on the popular messaging platform, sometimes in channels with tens of thousands of subscribers, lured by its ease of use and light-touch moderation.

A project of our size needs at least a few hundred million dollars per year to keep going,” Mr. Durov wrote in his public channel on Telegram late last year. “While doing that, we will remain independent and stay true to our values, redefining how a tech company should operate.

Rust from br


Telegram Rust
FROM USA