feat: init rust 101 crate
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
This commit is contained in:
parent
72ad1aafb7
commit
c1617c7ae2
|
@ -0,0 +1,6 @@
|
|||
.DS_Store
|
||||
.idea
|
||||
*.log
|
||||
tmp/
|
||||
|
||||
target
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,7 @@
|
|||
[workspace]
|
||||
|
||||
members = [
|
||||
"custom_rio",
|
||||
"rust_101",
|
||||
"tutotrial_cli",
|
||||
]
|
|
@ -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
|
|
@ -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]
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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"
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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]
|
|
@ -0,0 +1,3 @@
|
|||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
Loading…
Reference in New Issue