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

Unlimited members in Telegram group now

Telegram has made it easier for its users to communicate, as it has introduced a feature that allows more than 200,000 users in a group chat. However, if the users in a group chat move past 200,000, it changes into "Broadcast Group", but the feature comes with a restriction. Groups with close to 200k members can be converted to a Broadcast Group that allows unlimited members. Only admins can post in Broadcast Groups, but everyone can read along and participate in group Voice Chats," Telegram added.

A Telegram spokesman declined to comment on the bond issue or the amount of the debt the company has due. The spokesman said Telegram’s equipment and bandwidth costs are growing because it has consistently posted more than 40% year-to-year growth in users.

Rust from hk


Telegram Rust
FROM USA