§ 05Today I Learned今日所学

知识切片

代码片段、底层原理、工具技巧与即时思考的原子化沉淀。短小,但每一条都经过验证。

Entries
6条
Topics
6类
grep --tag
  1. #rust
    $til show 0001 --tag rust

    Rust 2024 Edition 中 async fn in trait 的生命周期推导规则

    在 Rust 2024 中,Trait 声明中的 async fn 默认隐式捕获所有输入参数的生命周期。

    trait Fetcher {
        // 编译器自动展开为: impl Future<Output = String> + use<'a, Self>
        async fn fetch<'a>(&'a self, key: &'a str) -> String;
    }

    当需要显式切断生命周期关联时,可以使用 + use<..> 精确捕获声明。

  2. #vue
    $til show 0002 --tag vue

    Vue 3.5 useId() 原理与 SSR 确定性水合

    Vue 3.5 引入了原生 useId() composable。它基于 App 根级计数器为每个组件生成确定性的唯一前缀,完美避免客户端与服务端水合时的 ID 不一致:

    const id = useId()
    // 服务端与客户端水合一致: 'v-0', 'v-1'
  3. #sqlite
    $til show 0003 --tag sqlite

    SQLite WAL 模式下的 checkpoint 机制与高并发读取优化

    开启 WAL (Write-Ahead Logging) 模式后,读者读操作完全不阻塞写操作。但 WAL 文件过大会影响读取性能,定期触发 PASSIVE 或 RESTART checkpoint 能将日志刷回主文件:

    PRAGMA journal_mode = WAL;
    PRAGMA wal_autocheckpoint = 1000;
  4. #css
    $til show 0004 --tag css

    CSS :has() 选择器与流体网格适配

    使用 :has() 可以在父元素层级感知子元素的结构与形态,彻底摆脱过去的 JS 布局注入:

    .article-grid:has(.featured-cover) {
      grid-template-columns: 2fr 1fr;
    }
  5. #python
    $til show 0005 --tag python

    Python 3.12+ PEP 695 泛型形参新语法

    Python 3.12 不再需要手动从 typing 模块导入 TypeVar:

    type Coordinate[T: (int, float)] = tuple[T, T]
    
    def identity[T](val: T) -> T:
        return val

    类型形参在作用域内自动惰性求值,清晰简洁。

  6. #git
    $til show 0006 --tag git

    Git worktree 打造零开销多分支并行工作流

    无需 git stash 频繁切换分支,直接开辟新工作树:

    git worktree add ../hotfix-branch hotfix
    cd ../hotfix-branch
    # 独立工作树,零冲突切换