RANDOM_RUST_DEV Telegram 86
Правильный ответ - inline const
https://doc.rust-lang.org/unstable-book/language-features/inline-const.html

Фикс

fn get_iter<'a, T>(q: Option<&'a VecDeque<T>>) -> std::collections::vec_deque::Iter<'a, T> {
q.unwrap_or(const { &VecDeque::new() }).iter()
}


Q: Почему это работает?
A: Создаваемая ссылка становится &'static.
Q: Почему нужен блок?
A: Потому что иначе rustc берет ссылку уже в runtime контексте и она на temporary значение.
🔥9👍1



tgoop.com/random_rust_dev/86
Create:
Last Update:

Правильный ответ - inline const
https://doc.rust-lang.org/unstable-book/language-features/inline-const.html

Фикс

fn get_iter<'a, T>(q: Option<&'a VecDeque<T>>) -> std::collections::vec_deque::Iter<'a, T> {
q.unwrap_or(const { &VecDeque::new() }).iter()
}


Q: Почему это работает?
A: Создаваемая ссылка становится &'static.
Q: Почему нужен блок?
A: Потому что иначе rustc берет ссылку уже в runtime контексте и она на temporary значение.

BY Random Rust Dev


Share with your friend now:
tgoop.com/random_rust_dev/86

View MORE
Open in Telegram


Telegram News

Date: |

End-to-end encryption is an important feature in messaging, as it's the first step in protecting users from surveillance. The initiatives announced by Perekopsky include monitoring the content in groups. According to the executive, posts identified as lacking context or as containing false information will be flagged as a potential source of disinformation. The content is then forwarded to Telegram's fact-checking channels for analysis and subsequent publication of verified information. The administrator of a telegram group, "Suck Channel," was sentenced to six years and six months in prison for seven counts of incitement yesterday. Don’t publish new content at nighttime. Since not all users disable notifications for the night, you risk inadvertently disturbing them. Matt Hussey, editorial director at NEAR Protocol also responded to this news with “#meIRL”. Just as you search “Bear Market Screaming” in Telegram, you will see a Pepe frog yelling as the group’s featured image.
from us


Telegram Random Rust Dev
FROM American