cowsay is like hello world
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/target
|
7
Cargo.lock
generated
Normal file
7
Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "cowsay"
|
||||
version = "0.1.0"
|
8
Cargo.toml
Normal file
8
Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "cowsay"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
27
src/cow.rs
Normal file
27
src/cow.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
use std::fmt;
|
||||
|
||||
const COW: &str = r#" \ ^__^
|
||||
\ (oo)\_______
|
||||
(__)\ )\/\
|
||||
||----w |
|
||||
|| ||"#;
|
||||
|
||||
pub struct Cow {
|
||||
text: String,
|
||||
cow: String,
|
||||
}
|
||||
|
||||
impl Cow {
|
||||
pub fn new(s: String) -> Cow {
|
||||
return Cow {
|
||||
text: s,
|
||||
cow: COW.to_string(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Cow {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "<{}>\n{}\n", self.text, self.cow)
|
||||
}
|
||||
}
|
10
src/main.rs
Normal file
10
src/main.rs
Normal file
@@ -0,0 +1,10 @@
|
||||
use std;
|
||||
mod cow;
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = std::env::args().collect();
|
||||
|
||||
let c = cow::Cow::new(args[1..].join(" "));
|
||||
|
||||
println!("{}", c)
|
||||
}
|
Reference in New Issue
Block a user