Files
rust-otus/practice/src/bin/a_compare.rs
2026-01-12 21:13:17 +03:00

22 lines
711 B
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Напиúите функøиĀ compare<T: PartialOrd>(a: T, b: T) -> T, котораā:
// ● Возвраûает наиболþúий из двух аргументов (a или b).
// ● Исполþзуйте трейт PartialOrd длā сравнениā.
#![allow(clippy::approx_constant)]
fn compare<T>(a: T, b: T) -> T
where
T: PartialOrd,
{
if a >= b { a } else { b }
}
fn main() {
println!("{}", compare(5, 10)); // 10
println!("{}", compare('a', 'z')); // z
// Также работает с другими типами, реализующими PartialOrd
println!("{}", compare(3.14, 2.71)); // 3.14
println!("{}", compare("apple", "banana")); // "banana"
}