| Crates.io | fcowsay |
| lib.rs | fcowsay |
| version | 2.0.0 |
| 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 |
| size | 9,471 |
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.