Вход на сайт

Просмотр новости

Найдите то, что Вас интересует

Thisversion: Keep schema history out of your application model

Дата публикации: 05-10-2026 12:39:46


Persisted data often outlives the code that wrote it. As an application evolves, its stored fields and their meanings change too. I built thisversion to keep that history in versioned schema types, while letting application code use one current model.
The idea for this library came from my place of work, where managing backwards compatibility became increasingly burdensome as our types accumulated changes over the years. I cleaned up and documented the approach so it could be useful to other Rust projects too.
With thisversion, you define a type for each schema version and write conversions between versions. Derives connect the schema history to your current application type, so Rust checks the connection when the model changes.
use thisversion::{VersionBoundary, VersionFamily};
use thisversion::traits::{IntoModel, IntoSchema};
#[derive(VersionFamily)]
enum SettingsVersions {
V1(SettingsV1),
V2(SettingsV2),
V3(SettingsV3),
}
// Historical schemas each have their own shape.
struct SettingsV1 { /* older schema */ }
struct SettingsV2 { /* newer fields */ }
#[derive(VersionBoundary)]
#[thisversion(model = Settings)]
struct SettingsV3 { /* current persisted schema */ }
// Migrations connect each historical schema to the next.
impl From<SettingsV1> for SettingsV2 { /* ... */ }
impl From<SettingsV2> for SettingsV3 { /* ... */ }
#[derive(VersionBoundary)]
#[thisversion(model = Settings)]
struct SettingsV3 { /* current persisted schema */ }
// Application code uses a completely isolated type.
struct Settings { /* current application model */ }
// Decode any stored version, then migrate it into the current model.
let versions: SettingsVersions = decode_from_somewhere(...);
let settings: Settings = versions.into_model();
// Convert back to the latest schema for persistence.
let schema: SettingsVersions = settings.into_schema();
The crate is no_std by default. Optional Serde adapters are available, but the migration layer does not require Serde or prescribe a storage system or wire format.
Links: crates.io · documentation · repository and examples
I'd love to get this to 1.0, but need some adoption and feedback before I feel comfortable committing to a 1.0 release.
The name is an homage thiserror and this is my first ever publication to crates.io!
1 post - 1 participant
Read full topic

Схожие новости

#Наименование новостиТональностьИнформативностьДата публикации
1Architecture review of a Hyper/Tower-based web framework (Toxi)015.4606-10-2026
2I built a library for automatic callback encoding/decoding for Teloxide08.2405-10-2026
3Strategies for dyn trait objects with optional behavior?07.1206-10-2026
4Adya 0.1: black-box transactional isolation checker (Elle-style) with a workload runner016.2806-10-2026
5Does my lockfree stack impl look correct?06.0605-10-2026
6What's everyone working on this week (41/2026)?020.3406-10-2026
7Are there wait-free priority queue crates?016.0905-10-2026
8Nuthatch: a blockchain indexer in one static Rust binary (redb, content-addressed Parquet, DataFusion, DBSP)08.2404-10-2026
9Why is f32/f64::sqrt not const?022.7206-10-2026
10Trait object with associated types in field - requires generic param?011.0807-10-2026

Классификация: . Схожих патентов: 0. Схожих новостей: 10. Тональность: 0. Информативность: 7.06. Источник: users.rust-lang.org.