| Crates.io | iphone |
| lib.rs | iphone |
| version | 0.1.0 |
| created_at | 2025-10-17 16:12:39.577007+00 |
| updated_at | 2025-10-17 16:12:39.577007+00 |
| description | Return the latest iPhone model, price (USD), and release date. |
| homepage | https://gitee.com/luzhihaoTestingLab/useful-cargo-packages |
| repository | https://gitee.com/luzhihaoTestingLab/useful-cargo-packages.git |
| max_upload_size | |
| id | 1887857 |
| size | 65,666 |
提供两种获取最新版 iPhone 信息的方式:
latest():离线回退,返回发布时已知的最新版(稳定、无网络)。fetch_latest():动态抓取,尝试从 Apple 官方页面解析型号、起售价与发布日期(需要网络)。返回结构体:
model: String — 型号,如 iPhone 17price_usd: Option<u32> — 美元起售价(若解析失败则为 None)release_date: Option<String> — 发布会日期(YYYY-MM-DD,若解析失败则为 None)在你的 Cargo.toml 中加入:
[dependencies]
iphone = "0.1"
示例(离线回退):
fn main() {
let latest = iphone::latest();
println!(
"最新 iPhone: {},起售价: {:?},发布日期: {:?}",
latest.model,
latest.price_usd,
latest.release_date,
);
}
示例(动态抓取):
fn main() {
match iphone::fetch_latest() {
Ok(info) => println!(
"最新 iPhone: {},起售价: {:?},发布日期: {:?}",
info.model, info.price_usd, info.release_date
),
Err(e) => eprintln!("抓取失败,使用回退: {}", e),
}
}
https://www.apple.com/iphone/ 抽取页面中出现的最大编号 iPhone XX 作为最新型号,并匹配 From $XXX 作为起售价线索。https://www.apple.com/newsroom/,就近匹配含有 iPhone 的区域周围的 time[datetime] 字段,作为发布日期近似值。latest() 的静态值。MIT