# 04-ecosystem **Repository Path**: czlan91/04-ecosystem ## Basic Information - **Project Name**: 04-ecosystem - **Description**: rust 第四周 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-05-16 - **Last Updated**: 2024-05-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Geektime Rust 语言训练营 rust 第四周 # tag v4-12-sqlx-url-shortener introduce sqlx and build url shortener v4-11-sqlx-url-shortener feature: introduce sqlx and build a url shortener v4-10-tokio-chat introduce tokio-util/tokio-stream/futures and build a chat server v4-9-tokio introduce tokio and a proxy example # commit feature: introduce sqlx and build a url shortener fix: fix typo and clippy issues feature: introduce tokio-util/tokio-stream/futures and write a chat server feature: introduce tokio and tokio proxy ## 添加依赖 ```shell cargo add anyhow cargo add thiserror cargo add serde --features derive --dev cargo add serde-json --dev cargo add axum --features http2 --features query --features tracing --dev cargo add tracing cargo add tracing-subscriber --features env-filter cargo add tracing-appender cargo add opentelemetry-otlp --features tonic cargo add opentelemetry cargo add opentelemetry-sdk --features rt-tokio cargo add tracing-opentelemetry cargo add chrono --features serde cargo add derive_builder --dev cargo add derive-more --dev cargo add strum --features derive --dev cargo add serde --features derive cargo add serde_json cargo add chacha20poly1305 cargo add serde_with cargo add base64 --dev cargo add http --dev cargo add bytes --dev cargo add blake3 --dev cargo add tokio --features rt --features rt-multi-thread --features macros --features fs --dev cargo add console-subscriber --dev cargo add dashmap --dev cargo add futures --dev cargo add loom --dev--dev cargo add tokio-util --features codec --dev cargo add tokio-stream --dev cargo add sqlx --dev --features postgres --features runtime-tokio --features tls-rustls cargo add nanoid --dev ``` ## Jaeger ```shell docker run -d -p16686:16686 -p4317:4317 -e COLLECTOR_OTLP_ENABLED=true jaegertracing/all-in-one:latest ``` ## 关于 OpenTelemetry 与 tracing 的 版本关系 可以通过 tracing-opentelemetry github仓库找到 https://github.com/tokio-rs/tracing-opentelemetry/blob/v0.1.x/Cargo.toml # 查看 tokio 运行时 ```shell cargo expand --example tokio1 ``` ```rust #![feature(prelude_import)] #[prelude_import] use std::prelude::rust_2021::*; #[macro_use] extern crate std; use std::{thread, time::Duration}; use tokio::{ fs, runtime::{Builder, Runtime}, time::sleep, }; fn main() { let handle = thread::spawn(|| { let rt = Builder::new_current_thread().enable_all().build().unwrap(); rt.block_on(run(&rt)); }); handle.join().unwrap(); } fn expensive_blocking_task(s: String) -> String { thread::sleep(Duration::from_millis(800)); blake3::hash(s.as_bytes()).to_string() } async fn run(rt: &Runtime) { rt.spawn(async { { ::std::io::_print(format_args!("future 1\n")); }; let content = fs::read("Cargo.toml").await.unwrap(); { ::std::io::_print(format_args!("content: {0:?}\n", content.len())); }; }); rt.spawn(async { { ::std::io::_print(format_args!("future 2\n")); }; let result = expensive_blocking_task("hello".to_string()); { ::std::io::_print(format_args!("result: {0}\n", result)); }; }); sleep(Duration::from_secs(1)).await; } ```