Introduction
Knowleadge base
Rust mdbook
Github Actions
work with mdbook
mdbook.yml
# Sample workflow for building and deploying a mdBook site to GitHub Pages
#
# To get started with mdBook see: https://rust-lang.github.io/mdBook/index.html
#
name: Deploy mdBook site to Pages
on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
# Build job
build:
runs-on: ubuntu-latest
env:
MDBOOK_VERSION: 0.4.36
steps:
- uses: actions/checkout@v4
- name: Install mdBook
run: |
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf -y | sh
rustup update
cargo install --version ${MDBOOK_VERSION} mdbook
- name: Setup Pages
id: pages
uses: actions/configure-pages@v5
- name: Build with mdBook
run: mdbook build
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./book
# Deployment job
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
Configuring a subdomain
To set up a www or custom subdomain, such as www.example.com or blog.example.com, you must add your domain in the repository settings. After that, configure a CNAME record with your DNS provider.
On GitHub, navigate to your site's repository.
Under your repository name, click Settings. If you cannot see the "Settings" tab, select the dropdown menu, then click Settings.
Screenshot of a repository header showing the tabs. The "Settings" tab is highlighted by a dark orange outline. In the "Code and automation" section of the sidebar, click Pages.
Under "Custom domain", type your custom domain, then click Save. If you are publishing your site from a branch, this will create a commit that adds a CNAME file directly to the root of your source branch. If you are publishing from a custom GitHub Actions workflow, no CNAME file is created, and any existing CNAME file is ignored and is not required. For more information about your publishing source, see Configuring a publishing source for your GitHub Pages site.
Note If your custom domain is an internationalized domain name, you must enter the Punycode encoded version. For more information on Punycodes, see Internationalized domain name.
Navigate to your DNS provider and create a CNAME record that points your subdomain to the default domain for your site. For example, if you want to use the subdomain www.example.com for your user site, create a CNAME record that points www.example.com to
Warning We strongly recommend that you do not use wildcard DNS records, such as *.example.com. These records put you at an immediate risk of domain takeovers, even if you verify the domain. For example, if you verify example.com this prevents someone from using a.example.com but they could still take over b.a.example.com (which is covered by the wildcard DNS record). For more information, see Verifying your custom domain for GitHub Pages.
HTTPS, Let’s Encrypt
Github pages already support Custom domain enforce HTTPS.
AI frameworks
candle
Candle: Simplicity and High-Performance ~ Deep Learning ~
burn
Burn: A Comprehensive Machine Learning Stack
Installation
Reading Books
Creating a Book
clap
examples
https://github.com/clap-rs/clap/blob/master/examples
config
Layered configuration system for Rust applications (with strong support for 12-factor applications).
Set defaults Set explicit values (to programmatically override) Read from JSON, TOML, YAML, INI, RON, JSON5 files Read from environment Loosely typed — Configuration values may be read in any supported type, as long as there exists a reasonable conversion Access nested fields using a formatted path — Uses a subset of JSONPath; currently supports the child ( redis.port ) and subscript operators ( databases[0].name )
Please note that this library can not be used to write changed configuration values back to the configuration file(s)!
references
- https://12factor.net/config
examples
https://github.com/rust-cli/config-rs/tree/main/examples
trace/log
Overview tracing is a framework for instrumenting Rust programs to collect structured, event-based diagnostic information. tracing is maintained by the Tokio project, but does not require the tokio runtime to be used. https://github.com/tokio-rs/tracing
crate
tracing
https://docs.rs/tracing/latest/tracing/
tracing_subscriber
https://docs.rs/tracing-subscriber/latest/tracing_subscriber/ Utilities for implementing and composing tracing subscribers.
tracing_log
https://docs.rs/tracing-log/latest/tracing_log/ Adapters for connecting unstructured log records from the log crate into the tracing ecosystem.
env_logger
A simple logger that can be configured via environment variables https://docs.rs/env_logger/latest/env_logger/
log
https://docs.rs/log/0.4.26/log/index.html A lightweight logging facade.
differences
log 和其他前端显示如 env_logger 组合可以实现 logger tracing 与其他可以实现在 async 世界的 logger?
references
https://tokio.rs/tokio/topics/tracing https://www.shuttle.dev/blog/2024/01/09/getting-started-tracing-rust
tokios
tokio and firends
tracing
bytes
mio
prost
tokio
tower
hyper
tonic
tower/hyper
Service trait
MakeService
axum
HTTP
PS: HTTP 更适合物联网/机器人系统中的“管理层”和“服务层”通信,不适合底层实时控制。 • 应用场景:设备初始化配置、参数下发、OTA 升级控制等。 • 优势: • 易于实现和调试,支持 REST API。 • 通过浏览器即可访问,非常适合调试和设备管理。 • 例子: • http://192.168.1.100/config 获取设备配置。 • POST /update-firmware 下发 OTA 升级命令。
router
Command Line Tool
init
build
watch
serve
test
clean
completions
Format
SUMMARY.md
Configuration
General
Preprocessors
Renderers
Environment Variables
Theme
index.hbs
Syntax highlighting
Editor
MathJax Support
mdBook-specific features
Markdown
Continuous Integration
For Developers
Preprocessors
Alternative Backends
Black hat Rust 2024
https://kerkour.com/tags/summer-of-rust-2024