Prelude: Why I didn't want to use serde-json Last week, I was looking into exploring ActivityPub, the protocol that powers Mastodon and the Fediverse. It uses a standard format for its JSON payloads: JSON-LD Compacted Document Form. A simple ActivityPub activity could look like this: { "@context": "https://www.w3.org/ns/activitystreams", "type": "Note", "to": ["https://chatty.example/ben/"], "attr
JSONはREST API呼び出し、データ保存、多言語との連携などに数多く使用されている。 一方で、JSONは言語でサポートされる表現が整数と浮動小数点数・文字列・配列・オブジェクト・そしてnull程度しかなく、それ以上に複雑な表現はこれらの基本機能を組み合わせて表現することになる。 機能の組み合わせ方には複数の方法があり、特に複数の型の構造体やクラスが混在する時の表現形式は複数ある。 Rustでは、表現したいデータ型が既知であれば、複数の型のうちどれかであることを表現するために列挙型が使える。 そして、Rustのシリアライザ・デシリアライザのライブラリであるserdeを用いて、列挙型とJSONの相互変換をすることができる。 列挙体の4種の表現 serdeで取り扱える列挙体の表現形式は4種類ある*1。 それぞれexternally tagged、internally tagged、adja
概要 serde の内部構造を解説するシリーズの第2回です。今回は serialize に焦点を当てて、解説します。 かなり長くなりましたが、コードは多めなので、楽しんで読んでいただけると思います。 1. serde の基本 2. serialize を読む 3. deserialize を読む 1 (予定) 4. deserialize を読む 2 (予定) 5. deserialize を読む 3 (予定) 6. formats (予定) まとめ Rust の強みである「単相化・インライン化を使ったゼロコスト抽象化」により、パフォーマンスを犠牲にすることなく serialize の実装を行うことができる。 serializer プロトタイピング: ゼロコスト抽象化編 他の言語の serializer と比較した時の serde の serializer serialize は、実はさほ
概要1: Rust の serde は面白いです。そこで、serde の内部構造を解説します。何回かに分けて詳しく見ていきたいと思います。 1. serde の基本 2. serialize を読む 3. deserialize を読む 1 (予定) 4. deserialize を読む 2 (予定) 5. deserialize を読む 3 (予定) 6. formats (予定) はじめに serde は直列化 (serialize) および直列化復元 (deserialize) を行うためのライブラリです。様々なデータ型、様々なデータフォーマットに対して直列化処理というものがジェネリクスを用いて統一的に記述できます。 ジェネリクスを使い、データフォーマット側とデータ型側で分離した設計にしている2理由は、公式のドキュメントにあります。以下 serde 公式 より引用: Design W
Two years ago I wrote an article about working with JSON in Rust. JSON (de)serialization support was then baked in the standard library. However, at that time Rust was at version 0.13 and a lot of things happened since then. Mainly, the rustc-serialize crate got pulled out of the core libraries, but kept its close relation to the rustc compiler itself. (Hence the slightly awkward name.) Meanwhile,
Serde Serde is a framework for serializing and deserializing Rust data structures efficiently and generically. The Serde ecosystem consists of data structures that know how to serialize and deserialize themselves along with data formats that know how to serialize and deserialize other things. Serde provides the layer by which these two groups interact with each other, allowing any supported data s
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く