Movatterモバイル変換


[0]ホーム

URL:


crate

Keywordcrate 

Source
Expand description

A Rust binary or library.

The primary use of thecrate keyword is as a part ofextern crate declarations, which areused to specify a dependency on a crate external to the one it’s declared in. Crates are thefundamental compilation unit of Rust code, and can be seen as libraries or projects. More canbe read about crates in theReference.

extern craterand;extern cratemy_crateasthing;extern cratestd;// implicitly added to the root of every Rust project

Theas keyword can be used to change what the crate is referred to as in your project. If acrate name includes a dash, it is implicitly imported with the dashes replaced by underscores.

crate can also be used as in conjunction withpub to signify that the item it’s attached tois public only to other members of the same crate it’s in.

pub(crate)usestd::io::ErrorasIoError;pub(crate)enumCoolMarkerType { }pub structPublicThing {pub(crate) semi_secret_thing: bool,}

crate is also used to represent the absolute path of a module, wherecrate refers to theroot of the current crate. For instance,crate::foo::bar refers to the namebar inside themodulefoo, from anywhere else in the same crate.


[8]ページ先頭

©2009-2026 Movatter.jp