Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

50.1.1First project

50.1.1.1New project

We first initialize a new project with the init sub-command. It will create the folder, a Rust code file with a main function inside and a Cargo.toml file:

    Creating binary (application) package
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

We enter the hello folder and build the project:

   Compiling hello v0.1.0 (/tmp/tmp.iGVibFZrsl/hello)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.19s

We run the project, a Hello, world! is printed:

    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/hello`
Hello, world!

50.1.1.2Using a crate dependency

We add the text2art crate as a dependency:

    Updating crates.io index
warning: failed to write cache, path: /usr/local/cargo/registry/index/index.crates.io-1949cf8c6b5b557f/.cache/te/xt/text2art, error: Permission denied (os error 13)
      Adding text2art v1.0.2 to dependencies
    Updating crates.io index
warning: failed to write cache, path: /usr/local/cargo/registry/index/index.crates.io-1949cf8c6b5b557f/.cache/te/xt/text2art, error: Permission denied (os error 13)
     Locking 7 packages to latest Rust 1.95.0 compatible versions
      Adding aho-corasick v1.1.5
      Adding memchr v2.8.3
      Adding regex v1.10.6 (available: v1.13.1)
      Adding regex-automata v0.4.18
      Adding regex-syntax v0.8.11
      Adding text2art v1.0.2
      Adding unicode-segmentation v1.10.1 (available: v1.13.3)

See the added lines for the dependency into the project file:

[package]
name = "hello"
version = "0.1.0"
edition = "2024"

[dependencies]
text2art = "1.0.2"

We write now the new code into the src/main.rs file:

use text2art::BasicFonts;
use text2art::Font;
use text2art::Printer;

fn main() {
  let font = Font::from_basic(BasicFonts::Big).unwrap();
  let prntr = Printer::with_font(font);
  prntr.print_to_stdio("Hello, world!").ok();
}

We rebuild the application:

    Updating crates.io index
warning: failed to write cache, path: /usr/local/cargo/registry/index/index.crates.io-1949cf8c6b5b557f/.cache/te/xt/text2art, error: Permission denied (os error 13)
 Downloading crates ...
  Downloaded text2art v1.0.2
error: failed to open `/usr/local/cargo/registry/cache/index.crates.io-1949cf8c6b5b557f/text2art-1.0.2.crate`

Caused by:
  Permission denied (os error 13)
Fetching long content....

And run it to print the same message in ASCII Art: