Rustでバイナリクレート✕1, ライブラリクレート✕Nのワークスペース作成
mkdir workspace cargo new binarycrate --bin cargo new libs1 --lib cargo new libs2 --lib
workspace/Cargo.tomlを作成して
[workspace] members = [ "args", "libs1", "libs2", ]
これがいいのかわかってないのでコメントお待ちしております
hyper-tlsでHTTPSリクエスト(not HTTP)する備忘録
経緯
DMM APIがHTTPSリクエストしか許してくれず、かと言ってhyperでhttpsリクエストしようとすると
StringError("Invalid scheme for Http")
なのでhyper-tlsいれてリクエスト飛ばして解決しました
手順
Cargo.toml追記
hyper = { version = "0.14.23", features = ["full"] } tokio = { version = "1.22.0", features = ["full"] } hyper-tls = { version = "0.5.0" }
src/main.rs
use hyper::{body::HttpBody as _, Client}; use hyper_tls::HttpsConnector; use tokio::io::{self, AsyncWriteExt as _}; #[tokio::main(flavor = "current_thread")] async fn main() -> Result<(), Box<dyn std::error::Error>> { let https = HttpsConnector::new(); let client = Client::builder().build::<_, hyper::Body>(https); let mut res = client.get("https://api.dmm.com/affiliate/v3/ItemList?api_id=[app_Id]&affiliate_id=[affiliate_id]&site=FANZA&service=digital&floor=videoa&hits=10&sort=date&keyword=%e4%b8%8a%e5%8e%9f%e4%ba%9c%e8%a1%a3&output=json".parse()?).await?; println!("Status: {}", res.status()); println!("Headers:\n{:#?}", res.headers()); while let Some(chunk) = res.body_mut().data().await { let chunk = chunk?; io::stdout().write_all(&chunk).await? } Ok(()) }
参考
YewでHelloWorld: 備忘録
Yew動かすまでにやったことすべてのメモ
cargo new yewexample cd yewexample touch index.html cargo install --locked trunk
Cargo.toml追記
yew = { git = "https://github.com/yewstack/yew/", features = ["csr"]}
src/main.rsの編集
use yew::prelude::*; #[function_component(App)] fn app() -> Html { html! { <div> <h1>{ "Hello World" }</h1> <h2>{ "HellowWorld2" }</h2> </div> } } fn main() { yew::Renderer::<App>::new().render(); }
trunk serve --release
8080で確認
終わりに
WebGLのexampleとかもあるので面白そうだなとなってます
Ubuntu22.04にRustインストール:備忘録
sudo apt update && sudo apt upgrade && curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh # 聞かれるので1を選んだ 1) Proceed with installation (default) 2) Customize installation 3) Cancel installation >1 source $HOME/.cargo/env rustc -V > rustc 1.65.0 (897e37553 2022-11-02)
sqlboilerでsupabaseから構造体生成した: 備忘録
models_psqlフォルダに構造体を生成する
インストール
go install github.com/volatiletech/sqlboiler/v4@v4.13.0 go install github.com/volatiletech/sqlboiler/v4/drivers/sqlboiler-psql@v4.13.0
sqlboiler.toml
[psql] dbname = "postgres" host = "db.プロジェクトID.supabase.co" port = 5432 user = "postgres" pass = "自分のパスワード" sslmode = "disable" schema = "public" blacklist = ["migrations", "other"]
構造体生成
sqlboiler psql --output models_psql --pkgname models_psql --wipe