]> git.proxmox.com Git - rustc.git/blame - src/doc/rust-by-example/src/crates/lib.md
New upstream version 1.48.0~beta.8+dfsg1
[rustc.git] / src / doc / rust-by-example / src / crates / lib.md
CommitLineData
1b1a35ee 1# Creating a Library
2c00a5a8
XL
2
3Let's create a library, and then see how to link it to another crate.
4
48663c56 5```rust,ignore
2c00a5a8
XL
6pub fn public_function() {
7 println!("called rary's `public_function()`");
8}
9
10fn private_function() {
11 println!("called rary's `private_function()`");
12}
13
14pub fn indirect_access() {
15 print!("called rary's `indirect_access()`, that\n> ");
16
17 private_function();
18}
19```
20
416331ca 21```shell
2c00a5a8
XL
22$ rustc --crate-type=lib rary.rs
23$ ls lib*
24library.rlib
25```
26
27Libraries get prefixed with "lib", and by default they get named after their
f9f354fc
XL
28crate file, but this default name can be overridden by passing
29the `--crate-name` option to `rustc` or by using the [`crate_name`
2c00a5a8
XL
30attribute][crate-name].
31
dc9dc135 32[crate-name]: ../attribute/crate.md