4.1.8 更新实现
08-更新实现 — Comprehensive Rust
译文 · 基于 Comprehensive Rust
原文链接: https://google.github.io/comprehensive-rust/android/aidl/example-service/changing-implementation.html
4.1.8 更新实现
更新客户端与服务端代码以适配新 API。
birthday_service/src/lib.rs:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| // Copyright 2024 Google LLC
// SPDX-License-Identifier: Apache-2.0
impl IBirthdayService for BirthdayService {
fn wishHappyBirthday(
&self,
name: &str,
years: i32,
text: &[String],
) -> binder::Result<String> {
let mut msg = format!(
"Happy Birthday {name}, congratulations with the {years} years!",
);
for line in text {
msg.push('\n');
msg.push_str(line);
}
Ok(msg)
}
}
|
birthday_service/src/client.rs:
1
2
3
4
5
6
7
8
9
10
| // Copyright 2024 Google LLC
// SPDX-License-Identifier: Apache-2.0
let msg = service.wishHappyBirthday(
&name,
years,
&[
String::from("Habby birfday to yuuuuu"),
String::from("And also: many more"),
],
)?;
|