Telegram Group & Telegram Channel
🎯 Задача на владение (ownership) и ссылки в Rust

Напиши функцию longest_word<'a>(a: &'a str, b: &'a str) -> &'a str,
которая возвращает слово с наибольшей длиной из двух строк.

Но есть ограничение: ты не можешь копировать строки — только возвращать ссылку.

📌 Пример:


fn main() {
let s1 = String::from("pirate");
let s2 = String::from("gold");

let result = longest_word(&s1, &s2);
println!("Longest: {}", result); // 👉 "pirate"
}


🔍 Подсказка:

- Тебе нужно указать время жизни `'a` для всех аргументов и возвращаемого значения.
- Если ты не укажешь
'a, компилятор не поймёт, какая ссылка может жить дольше.
- Возвращать
String нельзя — только &str (ссылка на строку).

🚫 Нельзя:

return a.to_string(); // копирование строки


Можно:

return a; // ссылка

@rust_code



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

🎯 Задача на владение (ownership) и ссылки в Rust

Напиши функцию longest_word<'a>(a: &'a str, b: &'a str) -> &'a str,
которая возвращает слово с наибольшей длиной из двух строк.

Но есть ограничение: ты не можешь копировать строки — только возвращать ссылку.

📌 Пример:


fn main() {
let s1 = String::from("pirate");
let s2 = String::from("gold");

let result = longest_word(&s1, &s2);
println!("Longest: {}", result); // 👉 "pirate"
}


🔍 Подсказка:

- Тебе нужно указать время жизни `'a` для всех аргументов и возвращаемого значения.
- Если ты не укажешь
'a, компилятор не поймёт, какая ссылка может жить дольше.
- Возвращать
String нельзя — только &str (ссылка на строку).

🚫 Нельзя:

return a.to_string(); // копирование строки


Можно:

return a; // ссылка

@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/967

View MORE
Open in Telegram


Rust Telegram | DID YOU KNOW?

Date: |

How to Buy Bitcoin?

Most people buy Bitcoin via exchanges, such as Coinbase. Exchanges allow you to buy, sell and hold cryptocurrency, and setting up an account is similar to opening a brokerage account—you’ll need to verify your identity and provide some kind of funding source, such as a bank account or debit card. Major exchanges include Coinbase, Kraken, and Gemini. You can also buy Bitcoin at a broker like Robinhood. Regardless of where you buy your Bitcoin, you’ll need a digital wallet in which to store it. This might be what’s called a hot wallet or a cold wallet. A hot wallet (also called an online wallet) is stored by an exchange or a provider in the cloud. Providers of online wallets include Exodus, Electrum and Mycelium. A cold wallet (or mobile wallet) is an offline device used to store Bitcoin and is not connected to the Internet. Some mobile wallet options include Trezor and Ledger.

In many cases, the content resembled that of the marketplaces found on the dark web, a group of hidden websites that are popular among hackers and accessed using specific anonymising software.“We have recently been witnessing a 100 per cent-plus rise in Telegram usage by cybercriminals,” said Tal Samra, cyber threat analyst at Cyberint.The rise in nefarious activity comes as users flocked to the encrypted chat app earlier this year after changes to the privacy policy of Facebook-owned rival WhatsApp prompted many to seek out alternatives.Rust from in


Telegram Rust
FROM USA