feat: init rust 101 crate

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
This commit is contained in:
Vincenzo Palazzo 2023-01-27 15:54:43 +01:00
parent 72ad1aafb7
commit c1617c7ae2
Signed by: vincenzopalazzo
GPG Key ID: 8B6DC2B870B80D5F
10 changed files with 1171 additions and 0 deletions

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
.DS_Store
.idea
*.log
tmp/
target

1050
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

7
Cargo.toml Normal file
View File

@ -0,0 +1,7 @@
[workspace]
members = [
"custom_rio",
"rust_101",
"tutotrial_cli",
]

27
Makefile Normal file
View File

@ -0,0 +1,27 @@
CC=cargo
FMT=fmt
OPTIONS=
default: fmt
$(CC) build
fmt:
$(CC) fmt --all
check:
$(CC) test --all -- --show-output --nocapture
example:
@echo "No example yet"
init:
cd specs; git clone https://github.com/lightning/bolts.git
make spec
spec:
cd specs; make all
clean:
$(CC) clean
@rm -rf specs/*.csv specs/bolts

8
custom_rio/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "custom_rio"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

14
custom_rio/src/lib.rs Normal file
View File

@ -0,0 +1,14 @@
pub fn add(left: usize, right: usize) -> usize {
left + right
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}

9
rust_101/Cargo.toml Normal file
View File

@ -0,0 +1,9 @@
[package]
name = "rust_101"
version = "0.1.0"
edition = "2021"
[dependencies]
reqwest = { version = "0.11", features = ["blocking"] }
log = "0.4"
env_logger = "0.9.1"

39
rust_101/src/lib.rs Normal file
View File

@ -0,0 +1,39 @@
#![allow(dead_code)]
use log::{debug, info};
// Name your user agent after your app?
static APP_USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"),);
/// Make an http request to Github API and return the result.
fn ping_github() -> Result<String, reqwest::Error> {
debug!("Running the https request");
let client = reqwest::blocking::Client::builder()
.user_agent(APP_USER_AGENT)
.build()?;
let resp = client.get("http://api.github.com/octocat").send()?;
let body = resp.text()?;
info!("{}", body);
Ok(body)
}
#[cfg(test)]
mod tests {
use std::sync::Once;
use crate::ping_github;
static INIT: Once = Once::new();
fn init() {
// ignore error
INIT.call_once(|| {
env_logger::init();
});
}
#[test]
fn safety_test() {
init();
let _ = ping_github().unwrap();
}
}

8
tutotrial_cli/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "tutotrial_cli"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View File

@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}