Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

Rust – Creating a Library

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Rust is a multi-paradigm programming language like C++ syntax that was designed for performance and safety, especially for safe concurrency. Also, it is a compiled system programming language. In this article, we will see how to create libraries in Rust.

Creating a Rust Library:

Step 1: We start by creating a .rs file called This file contains the contents of our library.



// Name of the file =
pub fn public_function() {
    println!("Hello I am a public function");
fn private_function() {
    println!("Hello I am a private function");
pub fn indirect_access() {
    print!("Accessing a private library using a public function");
fn main(){



Step 2: Now we will create this library using the following command.

$ rustc --crate-type=lib

Step 3: The above command will generate file “library.rlib” . All libraries get prefixed with “lib” and by default, they are named after their create file. So “library.rlib” –> lib + rary + .rlib

Step 4: The following command can override the default name.

$ rustc --crate-type=lib --create-name "<Name of your choice>"

So, by using the above steps you can create our own Rust library.

My Personal Notes arrow_drop_up
Last Updated : 04 Apr, 2023
Like Article
Save Article
Similar Reads