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

As of Thursday, the SUCK Channel had 34,146 subscribers, with only one message dated August 28, 2020. It was an announcement stating that police had removed all posts on the channel because its content “contravenes the laws of Hong Kong.” Matt Hussey, editorial director of NEAR Protocol (and former editor-in-chief of Decrypt) responded to the news of the Telegram group with “#meIRL.” Image: Telegram. Hui said the time period and nature of some offences “overlapped” and thus their prison terms could be served concurrently. The judge ordered Ng to be jailed for a total of six years and six months. 6How to manage your Telegram channel?
from us


Telegram Random Rust Dev
FROM American