Movatterモバイル変換


[0]ホーム

URL:


type

Keywordtype 

Source
Expand description

Define analias for an existing type.

The syntax istype Name = ExistingType;.

§Examples

type doesnot create a new type:

typeMeters = u32;typeKilograms = u32;letm: Meters =3;letk: Kilograms =3;assert_eq!(m, k);

A type can be generic:

typeArcMutex<T> = Arc<Mutex<T>>;

In traits,type is used to declare anassociated type:

traitIterator {// associated type declarationtypeItem;fnnext(&mutself) ->Option<Self::Item>;}structOnce<T>(Option<T>);impl<T> IteratorforOnce<T> {// associated type definitiontypeItem = T;fnnext(&mutself) ->Option<Self::Item> {self.0.take()    }}

[8]ページ先頭

©2009-2026 Movatter.jp