Skip to content

Commit

Permalink
Create rust minigrep structure
Browse files Browse the repository at this point in the history
  • Loading branch information
rxqd committed Mar 29, 2024
1 parent 5fe87bc commit 07db91f
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 4 deletions.
20 changes: 20 additions & 0 deletions src/rust/minigrep/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Cargo allow list

# Ignore everything
*
# ...even if they are in subdirectories
!*/

# But not these files...
!/.gitignore

!*.rs
!Cargo.toml
!Cargo.lock

!README.md
!LICENSE
!/docs/
!/Makefile
!/run.sh
!/.replit
8 changes: 8 additions & 0 deletions src/rust/minigrep/.replit
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
hidden = ["target", ".cargo"]
run = "bash current/run.sh"

modules = ["rust-stable:v10-20240306-8675cf9"]

[nix]
channel = "stable-23_11"

7 changes: 7 additions & 0 deletions src/rust/minigrep/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/rust/minigrep/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "minigrep"
version = "0.1.0"
authors = ["rust-tutorial"]
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
4 changes: 4 additions & 0 deletions src/rust/minigrep/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

current_dir=$(dirname "$(readlink -f "$0")")
cargo run --manifest-path "$current_dir/Cargo.toml"
17 changes: 17 additions & 0 deletions src/rust/minigrep/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
fn main() {
println!("{}", hello());
}

pub fn hello() -> String {
"Hello rust".to_string()
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_hello() {
assert_eq!(hello(), "Hello rust");
}
}
7 changes: 3 additions & 4 deletions templates/rust/app/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

fn main() {
println!(hello());
println!("{}", hello());
}

pub fn hello() -> 'static &str {
"Hello rust"
pub fn hello() -> String {
"Hello rust".to_string()
}

#[cfg(test)]
Expand Down

0 comments on commit 07db91f

Please sign in to comment.