4 多态
多态 — Comprehensive Rust
译文 · 基于 Comprehensive Rust
原文链接: https://google.github.io/comprehensive-rust/idiomatic/polymorphism.html
4 多态
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| // Copyright 2025 Google LLC
// SPDX-License-Identifier: Apache-2.0
pub trait Trait {}
pub struct HasGeneric<T>(T);
pub enum Either<A, B> {
Left(A),
Right(B),
}
fn takes_generic<T: Trait>(value: &T) {}
fn takes_dyn(value: &dyn Trait) {}
|
要点回顾 — Comprehensive Rust
从 OOP 到 Rust — Comprehensive Rust