Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Полиморфизм

// 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) {}
This slide should take about 2 minutes.
  • В Rust есть множество механизмов для написания и использования полиморфного кода, но они заметно отличаются от других популярных языков!

  • В этой главе мы разберём подробности полиморфизма Rust и то, чем он похож на полиморфизм в других языках или отличается от него.