Crates.io | fcowsay |
lib.rs | fcowsay |
version | |
source | src |
created_at | 2025-03-15 10:16:11.604434+00 |
updated_at | 2025-03-15 10:16:11.604434+00 |
description | Rust Library for working with cowsay |
homepage | https://github.com/linuxfanboy4/fcowsay.git |
repository | https://github.com/linuxfanboy4/fcowsay.git |
max_upload_size | |
id | 1593452 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
fcowsay
is a comprehensive Rust library designed to facilitate the generation of animal sayings in a manner reminiscent of the classic cowsay
utility. This library provides a robust and extensible framework for creating and customizing animal-based ASCII art with associated messages. It is particularly suited for developers seeking to integrate whimsical or informative animal-based text displays into their Rust applications.
To integrate fcowsay
into your Rust project, add the following dependency to your Cargo.toml
:
[dependencies]
fcowsay = "2.0.0"
To generate a saying using the default cow:
use fcowsay::animalsay;
fn main() {
let message = "Hello, world!";
let animal = "cow";
let output = animalsay(message, animal);
println!("{}", output);
}
This will produce the following output:
----------------------------------------
| Hello, world! |
----------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
You can specify different animals by changing the animal
parameter:
use fcowsay::animalsay;
fn main() {
let message = "Rust is awesome!";
let animal = "dragon";
let output = animalsay(message, animal);
println!("{}", output);
}
This will produce the following output:
----------------------------------------
| Rust is awesome! |
----------------------------------------
\ \=====
\ (o o)
| ~|
(_____)
For more advanced usage, you can directly use the AnimalSay
struct to customize the message width and other parameters:
use fcowsay::AnimalSay;
fn main() {
let animal_say = AnimalSay::new("Custom width and animal", "cat");
let output = animal_say.say();
println!("{}", output);
}
This will produce the following output:
----------------------------------------
| Custom width and animal |
----------------------------------------
\ /\_/\
\ ( o.o )
> ^ <
To add a new animal, simply extend the animal_art_map
function within the AnimalSay
implementation:
impl AnimalSay {
fn animal_art_map() -> HashMap<&'static str, &'static str> {
let mut animals = HashMap::new();
animals.insert("cow", " \\ ^__^\n \\ (oo)\\_______\n (__)\\ )\\/\\\n ||----w |\n || ||");
animals.insert("sheep", " \\ (__) \n \\ (oo)\\_______\n (__)\\ )\\/\\\n ||----w |\n || ||");
animals.insert("dragon", " \\ \\=====\n \\ (o o)\n | ~| \n (_____)");
animals.insert("cat", " \\ /\\_/\\\n \\ ( o.o )\n > ^ <");
animals.insert("new_animal", " \\ New Art\n \\ (o o)\n | ~| \n (_____)");
animals
}
}
Then, you can use the new animal by specifying it in the animalsay
function or AnimalSay
struct.
Contributions to fcowsay
are welcome! Whether it's adding new animals, improving the message wrapping algorithm, or enhancing the API, your contributions can help make fcowsay
even more robust and versatile.
fcowsay
is distributed under the MIT License. See the LICENSE
file for more details.
For any inquiries or suggestions, please contact Calestial Ashley at calestialashley@gmail.com.