Rust concurrency — Send and Sync marker traits

聊聊Rust的并发约束:Send和Sync

A lot of Rust’s thread safety is two auto traits: Send (OK to move to another thread) and Sync (OK to share as &T). The compiler checks them at thread::spawn and when references cross threads.

Read More

Rust shared ownership — Rc, Arc, and weak references

聊聊共享所有权之Rc和Arc

One owner

Rust’s ownership model says each value has one owner. When the owner goes out of scope, the value is dropped.

In the snippet below, if a is moved into b, you cannot print a afterward — ownership already moved.

Read More

Rust interior mutability — Cell and RefCell

聊聊Rust的Cell和RefCell

Interior mutability means a value looks immutable from the outside but can still be changed on the inside. It shows up when you hold an immutable reference and still need to update the data.

Cell and RefCell are Rust’s two main options. Cell targets Copy types; RefCell handles non-Copy types.

When do you actually reach for them, and why two types? Below are a few concrete situations.

Read More

Rust ownership from scratch — move, borrow, lifetimes, and memory safety

掌握Rust:从零开始的所有权之旅

Ownership is one of Rust’s most distinctive features — and one of the hardest for newcomers.

Ownership trips up most Rust beginners. The examples below show what it is, why the compiler cares, and how move, borrow, and lifetimes fit together. Skim once for the map; come back for the line-by-line bits.

Tip: The code has comments. You don’t need every detail on the first pass — follow the flow, then dig into specific snippets later.

Read More

Code as liability, not an asset — from Software Engineering at Google

代码是负债,而不是资产

I’ve been reading Software Engineering at Google, and one line stuck with me:

Code is a liability, not an asset.

If you’re a programmer, that probably sounds wrong. Your code feels like something you built — proof of skill. How could it be a liability?

Read More

Keycloak external auth — Google IDP, token exchange, and an Axum demo

深入解读-如何用keycloak管理external auth

Most of us have at least heard of OAuth2.

New to the vocabulary? Skim Authentication vs authorization — OAuth2, OIDC, JWT, and Keycloak for the basics and flows.

With Google as the IdP, the usual story: user hits the consent screen, comes back with an authorization code, you exchange it for tokens, then call Google APIs on the user’s behalf.

Rolling that by hand isn’t huge — but add Facebook, Instagram, and every other IdP and you don’t want N custom integrations. A central auth layer is the point. Here we use Keycloak as that layer.

If you can’t reproduce it locally, it’s hard to learn or debate the design. This walkthrough uses Rust/Axum + Keycloak, with docker-compose, Terraform, and shell scripts so you can replay the whole stack on a Mac. Repo: https://github.com/NewbMiao/axum-koans

Read More

Docker layer caching for Rust Cargo dependencies

如何在docker中缓存加速Rust依赖构建

I was working through Chen Tian’s Programming Rust course and building the sample code in Docker. Every run spent time refreshing the crates.io index—even when Cargo.toml had not changed.

There has to be a way to cache that. This is the path I took (including what did not work).

Read More

Authentication vs authorization — OAuth2, OIDC, JWT, and Keycloak

简单聊聊鉴权背后的那些技术

I put together a small Keycloak auth demo so folks who’ve never touched Keycloak can see the moving parts without drowning in docs.

Goes with the Keycloak demo above: authentication vs authorization, OAuth2, OpenID Connect, JWT, JWKS—and where each shows up in that code.

Read More