mirror of
https://github.com/gnu4cn/rust-lang-zh_CN.git
synced 2026-08-22 06:03:27 +08:00
reorganized the directories
This commit is contained in:
8
projects/lifetimes_demo/Cargo.toml
Normal file
8
projects/lifetimes_demo/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "lifetimes_demo"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
23
projects/lifetimes_demo/src/main.rs
Normal file
23
projects/lifetimes_demo/src/main.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
fn longest_with_an_announcement<'a, T>(
|
||||
x: &'a str,
|
||||
y: &'a str,
|
||||
ann: T,
|
||||
) -> &'a str
|
||||
where
|
||||
T: Display,
|
||||
{
|
||||
println! ("通知!{}", ann);
|
||||
if x.len() > y.len() {
|
||||
x
|
||||
} else {
|
||||
y
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let result = longest_with_an_announcement("abc", "测试", "计算结果已出来。");
|
||||
|
||||
println! ("{}", result);
|
||||
}
|
||||
Reference in New Issue
Block a user