fixed_record/lib.rs
1//! Fixed-width record helpers generated from plain Rust structs.
2//!
3//! `fixed-record` lets application code describe a fixed-width record once as a Rust struct,
4//! then use generated builders, parsers, field accessors, stream readers/writers, and searchable
5//! list APIs.
6//!
7//! `fixed-record` は、固定長レコードのレイアウトを Rust の struct として一度だけ定義し、
8//! builder、parser、フィールド accessor、stream 用 Reader/Writer、検索可能な List API を
9//! 生成して使うための crate です。
10//!
11//! Most users should depend only on this crate and import [`prelude`].
12//! The `fixed-record-macros` crate is the proc-macro implementation detail re-exported here.
13//!
14//! 通常の利用者はこの crate だけに依存し、[`prelude`] を import すれば十分です。
15//! `fixed-record-macros` はここから再エクスポートされる proc macro 実装用 crate です。
16//!
17//! # Installation / インストール
18//!
19//! Before the crate is published to crates.io, depend on the Git repository.
20//!
21//! crates.io に公開する前は、Git repository 依存として追加します。
22//!
23//! ```toml
24//! [dependencies]
25//! fixed-record = { git = "https://github.com/tomi-912/fixed-record.git" }
26//! ```
27//!
28//! After publishing to crates.io, use the versioned dependency.
29//!
30//! crates.io 公開後は、version 指定の依存として追加できます。
31//!
32//! ```toml
33//! [dependencies]
34//! fixed-record = "0.1"
35//! ```
36//!
37//! # Define a Record / レコードを定義する
38//!
39//! Add [`macro@fixed_record`] to a struct whose fields are [`Fixed<N>`](Fixed). Each field width is
40//! a byte width, not a character count.
41//!
42//! [`macro@fixed_record`] を [`Fixed<N>`](Fixed) フィールドだけを持つ struct に付けます。
43//! 各フィールド幅は文字数ではなくバイト数です。
44//!
45//! ```
46//! use fixed_record::prelude::*;
47//!
48//! #[fixed_record]
49//! struct Order {
50//! customer_id: Fixed<4>,
51//! order_no: Fixed<6>,
52//! amount: Fixed<8>,
53//! }
54//!
55//! assert_eq!(Order::TOTAL_LEN, 18);
56//! assert_eq!(Order::FIELD_SIZE_CUSTOMER_ID, 4);
57//! assert_eq!(Order::offset_of(OrderField::Amount), 10);
58//! assert_eq!(Order::name_of(OrderField::OrderNo), "order_no");
59//! assert_eq!(OrderField::Amount.as_str(), "amount");
60//! assert_eq!(OrderField::Amount.size(), 8);
61//! ```
62//!
63//! Generated names follow the input struct:
64//!
65//! 生成名は入力 struct から決まります。
66//! `OrderField` and `OrderList` use the same visibility as `Order`.
67//! `OrderField` と `OrderList` は `Order` と同じ可視性で生成されます。
68//!
69//! - `Order`: the record type / レコード型
70//! - `OrderField`: the field enum / フィールド enum
71//! - `OrderList`: the searchable list type when the default `list` feature is enabled /
72//! default feature の `list` が有効な場合の検索用 list 型
73//!
74//! # Build Records / レコードを作成する
75//!
76//! `builder()` starts with `CLEAR_BYTE` padding. Plain `with_*` methods write from the beginning of
77//! the field, while numeric helpers write zero-padded strings.
78//!
79//! `builder()` は `CLEAR_BYTE` で埋めた値から開始します。通常の `with_*` はフィールド先頭から
80//! 上書きし、数値用 helper はゼロ埋め文字列を書き込みます。
81//!
82//! ```
83//! use fixed_record::prelude::*;
84//!
85//! #[fixed_record]
86//! struct Order {
87//! customer_id: Fixed<4>,
88//! order_no: Fixed<6>,
89//! amount: Fixed<8>,
90//! }
91//!
92//! let order = Order::builder()
93//! .with_customer_id("C001")
94//! .with_order_no("A00042")
95//! .with_amount_int(1250)
96//! .build();
97//!
98//! assert_eq!(order.customer_id(), b"C001");
99//! assert_eq!(order.order_no_str().unwrap(), "A00042");
100//! assert_eq!(order.amount(), b"00001250");
101//! assert_eq!(order.byte_len(), Order::TOTAL_LEN);
102//! ```
103//!
104//! Use `try_with_*_int` or `try_with_*_int_signed` when overflow must be an error. The non-`try`
105//! variants keep the leading bytes when a formatted number is too wide.
106//!
107//! 幅超過をエラーとして扱いたい場合は `try_with_*_int` / `try_with_*_int_signed` を使います。
108//! `try` なしの variant は、幅を超えた数値の先頭側を残します。
109//!
110//! ```
111//! use fixed_record::prelude::*;
112//!
113//! #[fixed_record]
114//! struct Balance {
115//! account: Fixed<4>,
116//! signed_amount: Fixed<6>,
117//! }
118//!
119//! let balance = Balance::builder()
120//! .with_account("A001")
121//! .try_with_signed_amount_int_signed(-42)
122//! .unwrap()
123//! .build();
124//!
125//! assert_eq!(balance.signed_amount(), b"-00042");
126//!
127//! let err = Balance::builder()
128//! .try_with_signed_amount_int_signed(-123456)
129//! .unwrap_err();
130//! assert!(matches!(err, fixed_record::Error::FieldOverflow { field: "signed_amount", .. }));
131//! ```
132//!
133//! # Parse and Serialize / パースとシリアライズ
134//!
135//! `parse` / `parse_str` read fixed-width bytes into an owned record. `to_bytes` copies the record
136//! back to its fixed-width byte array.
137//!
138//! `parse` / `parse_str` は固定長バイト列を所有値のレコードへ変換します。`to_bytes` はレコードを
139//! 固定長バイト配列へコピーして返します。
140//!
141//! ```
142//! use fixed_record::prelude::*;
143//!
144//! #[fixed_record]
145//! struct Order {
146//! customer_id: Fixed<4>,
147//! order_no: Fixed<6>,
148//! amount: Fixed<8>,
149//! }
150//!
151//! let raw = b"C001A0004200001250";
152//! let order = Order::parse(raw).unwrap();
153//!
154//! assert_eq!(order.get_field_trimmed(OrderField::CustomerId).unwrap(), "C001");
155//! assert_eq!(order.get_field_as::<u32>(OrderField::Amount).unwrap(), 1250);
156//! assert_eq!(order.to_bytes(), *raw);
157//!
158//! let same = Order::parse_str("C001A0004200001250").unwrap();
159//! assert_eq!(same.to_bytes(), *raw);
160//! ```
161//!
162//! # Dynamic Field Operations / 動的フィールド操作
163//!
164//! Field enum values let you write generic code that does not hard-code accessor method names.
165//! `set_field_*` clears the target field first; `set_field_*_no_clear` preserves trailing bytes.
166//!
167//! フィールド enum を使うと、accessor 名を固定せずに汎用的な処理を書けます。
168//! `set_field_*` は対象フィールドを先にクリアし、`set_field_*_no_clear` は後続バイトを残します。
169//!
170//! ```
171//! use fixed_record::prelude::*;
172//!
173//! #[fixed_record]
174//! struct Order {
175//! customer_id: Fixed<4>,
176//! order_no: Fixed<6>,
177//! amount: Fixed<8>,
178//! }
179//!
180//! let mut order = Order::spaced()
181//! .with_customer_id("C001")
182//! .with_order_no("A00042")
183//! .with_amount_int(1250)
184//! .build();
185//!
186//! order.set_field_str(OrderField::OrderNo, "B7");
187//! assert_eq!(order.order_no(), b"B7 ");
188//!
189//! order.set_field_str_no_clear(OrderField::OrderNo, "C8");
190//! assert_eq!(order.order_no(), b"C8 ");
191//!
192//! order.fill_field_zero(OrderField::Amount);
193//! assert_eq!(order.amount(), &[0, 0, 0, 0, 0, 0, 0, 0]);
194//! ```
195//!
196//! # Bulk Application Helpers / 一括流し込み helper
197//!
198//! `apply_bytes` and `apply_str` split input across fields in declaration order. The `_from`
199//! variants begin at a selected field.
200//!
201//! `apply_bytes` / `apply_str` は定義順にフィールド幅ごとに入力を流し込みます。`_from` variant は
202//! 指定フィールドから開始します。
203//!
204//! ```
205//! use fixed_record::prelude::*;
206//!
207//! #[fixed_record]
208//! struct Order {
209//! customer_id: Fixed<4>,
210//! order_no: Fixed<6>,
211//! amount: Fixed<8>,
212//! }
213//!
214//! let order = Order::spaced().apply_bytes(b"C001A0004200001250");
215//! assert_eq!(order.customer_id(), b"C001");
216//! assert_eq!(order.order_no(), b"A00042");
217//! assert_eq!(order.amount(), b"00001250");
218//!
219//! let changed_tail = Order::spaced()
220//! .with_customer_id("C999")
221//! .apply_str_from(OrderField::OrderNo, "B0007700000900");
222//!
223//! assert_eq!(changed_tail.customer_id(), b"C999");
224//! assert_eq!(changed_tail.order_no(), b"B00077");
225//! assert_eq!(changed_tail.amount(), b"00000900");
226//! ```
227//!
228//! # Reader and Writer / Reader / Writer
229//!
230//! [`Reader`] reads records sequentially from any `BufRead`. `Reader::new` expects LF (`\n`) after
231//! records. Use [`Reader::with_separator`] when the input uses a different separator or no
232//! separator. When configured, the separator must also appear after the final record. [`Writer`]
233//! writes `to_bytes()` output and appends LF by default.
234//!
235//! [`Reader`] は任意の `BufRead` から固定長レコードを順に読みます。`Reader::new` はレコード後ろに
236//! LF (`\n`) がある入力を想定します。別の区切り、または区切りなしの入力を読む場合は
237//! [`Reader::with_separator`] で指定します。区切りを設定した場合は、最終レコードの後ろにもその区切りが必要です。
238//! [`Writer`] は `to_bytes()` の結果を書き出し、デフォルトでは LF を付けます。
239//!
240//! ```
241//! use fixed_record::prelude::*;
242//! use std::io::{BufReader, Cursor};
243//!
244//! #[fixed_record]
245//! struct Order {
246//! customer_id: Fixed<4>,
247//! order_no: Fixed<6>,
248//! amount: Fixed<8>,
249//! }
250//!
251//! let first = Order::builder()
252//! .with_customer_id("C001")
253//! .with_order_no("A00001")
254//! .with_amount_int(100)
255//! .build();
256//! let second = Order::builder()
257//! .with_customer_id("C002")
258//! .with_order_no("A00002")
259//! .with_amount_int(200)
260//! .build();
261//!
262//! let mut output = Vec::new();
263//! let mut writer = Writer::new(&mut output)
264//! .with_separator(RecordSeparator::Crlf);
265//! writer.write_all([&first, &second]).unwrap();
266//! writer.flush().unwrap();
267//! drop(writer);
268//!
269//! let mut reader = Reader::<_, Order>::new(BufReader::new(Cursor::new(output)))
270//! .with_separator(RecordSeparator::Crlf);
271//! assert_eq!(reader.next().unwrap().unwrap().order_no(), b"A00001");
272//! assert_eq!(reader.next().unwrap().unwrap().order_no(), b"A00002");
273//! assert!(reader.next().is_none());
274//! ```
275//!
276//! Sequence checks can validate that input is sorted by selected fields.
277//!
278//! シーケンスチェックを使うと、入力が指定フィールド順に昇順であることを検証できます。
279//!
280//! ```
281//! use fixed_record::prelude::*;
282//! use std::io::{BufReader, Cursor};
283//!
284//! #[fixed_record]
285//! struct Order {
286//! customer_id: Fixed<4>,
287//! order_no: Fixed<6>,
288//! amount: Fixed<8>,
289//! }
290//!
291//! let first = Order::builder().with_customer_id("C001").with_order_no("A00001").with_amount_int(100).build();
292//! let second = Order::builder().with_customer_id("C001").with_order_no("A00002").with_amount_int(200).build();
293//!
294//! let mut input = Vec::new();
295//! input.extend_from_slice(&first.to_bytes());
296//! input.push(b'\n');
297//! input.extend_from_slice(&second.to_bytes());
298//! input.push(b'\n');
299//!
300//! let list = Reader::<_, Order>::new(BufReader::new(Cursor::new(input)))
301//! .with_sequence_check([OrderField::CustomerId, OrderField::OrderNo])
302//! .collect_list()
303//! .unwrap();
304//!
305//! assert_eq!(list.len(), 2);
306//! assert_eq!(list.try_find_by(OrderField::CustomerId, b"C001").unwrap().len(), 2);
307//! ```
308//!
309//! # Searchable Lists / 検索可能な List
310//!
311//! With the default `list` feature, the macro generates the optional helper `{StructName}List`. It
312//! stores boxed records in a vector and maintains ordered field-byte indexes for construction from
313//! a record vector, appending, position-based insertion, lookup, update, physical removal, popping
314//! the last record, sorting, exact searches, padded searches, prefix searches, range searches, and
315//! index-aware callback edits.
316//! `read_from` consumes a configured [`Reader`] and collects its remaining records into the List.
317//! Exact searches use the index directly instead of scanning every record.
318//! Search-based edits select private current indexes internally and repair affected index entries
319//! after the callback, without returning indexes or mutable references to the caller.
320//! Sorting moves boxes in the vector, not the record values allocated behind them.
321//! List IDs are the current vector indexes, so IDs can change after removal or sorting.
322//!
323//! default feature の `list` が有効な場合、macro は補助機能として `{StructName}List` を生成します。
324//! これは Box 化したレコードを vector に保持し、フィールドの実バイト列による順序付き索引を管理して、
325//! レコード vector からの構築、末尾追加、位置指定挿入、lookup、update、物理削除、末尾レコードの
326//! pop、sort、完全一致検索、padding を考慮した検索、prefix 検索、range 検索、索引対応の
327//! callback 変更を提供します。
328//! `read_from` は設定済みの [`Reader`] を消費し、残りのレコードを List へ収集します。
329//! 完全一致検索は全レコードを走査せず、索引を直接参照します。
330//! 検索条件付き変更は非公開の現在 index を内部で選択し、index や mutable 参照を呼び出し側へ返さず、
331//! callback 後に影響する索引項目を修復します。
332//! ソート時は vector 内の Box が移動し、Box の先にあるレコード本体は移動しません。
333//! List ID は現在の vector index なので、削除やソート後に変わる可能性があります。
334//!
335//! ```
336//! use fixed_record::prelude::*;
337//!
338//! #[fixed_record]
339//! struct Order {
340//! customer_id: Fixed<4>,
341//! order_no: Fixed<6>,
342//! amount: Fixed<8>,
343//! }
344//!
345//! let mut list: OrderList = vec![
346//! Order::builder()
347//! .with_customer_id("C001")
348//! .with_order_no("A00002")
349//! .with_amount_int(200)
350//! .build(),
351//! Order::builder()
352//! .with_customer_id("C001")
353//! .with_order_no("A00001")
354//! .with_amount_int(100)
355//! .build(),
356//! ].into();
357//! let id_first = 0;
358//! let id_second = 1;
359//!
360//! assert_eq!(list.len(), 2);
361//! assert_eq!(list.get(id_first).unwrap().amount(), b"00000200");
362//!
363//! let exact = list.try_find_by(OrderField::CustomerId, b"C001").unwrap();
364//! assert_eq!(exact.len(), 2);
365//!
366//! let first_exact = list.try_first_by(OrderField::OrderNo, b"A00001").unwrap().unwrap();
367//! assert_eq!(first_exact.amount(), b"00000100");
368//!
369//! let padded = list.try_find_by_padded(OrderField::OrderNo, b"A00001").unwrap();
370//! assert_eq!(padded[0].amount(), b"00000100");
371//!
372//! let prefix = list.try_find_by_prefix(OrderField::OrderNo, b"A000").unwrap();
373//! assert_eq!(prefix.len(), 2);
374//!
375//! let first_by_order_no = list.first_sorted_by(OrderField::OrderNo).unwrap();
376//! assert_eq!(first_by_order_no.order_no(), b"A00001");
377//!
378//! assert!(list.try_edit_first_by(OrderField::OrderNo, b"A00001", |order| {
379//! order.set_field_str(OrderField::Amount, "00000150");
380//! }).unwrap());
381//! assert_eq!(list.try_find_by(OrderField::Amount, b"00000150").unwrap().len(), 1);
382//!
383//! list.update(id_first, Order::builder()
384//! .with_customer_id("C002")
385//! .with_order_no("B00001")
386//! .with_amount_int(300)
387//! .build());
388//! assert!(list.try_find_by_padded(OrderField::CustomerId, b"C001").unwrap().len() == 1);
389//!
390//! list.for_each_mut(|order| order.set_field_str(OrderField::CustomerId, "C003"));
391//! assert_eq!(list.try_find_by(OrderField::CustomerId, b"C003").unwrap().len(), 2);
392//!
393//! assert!(list.remove(id_second));
394//! assert_eq!(list.len(), 1);
395//! assert_eq!(list.all_ids(), vec![id_first]);
396//! ```
397//!
398//! Fallible search methods use the `try_` prefix. Range searches accept byte-like bounds through
399//! [`ByteRangeBounds`](traits::ByteRangeBounds).
400//!
401//! 失敗する可能性がある検索メソッドは `try_` prefix を使います。range 検索は
402//! [`ByteRangeBounds`](traits::ByteRangeBounds) を通して byte 列として扱える境界値を受け取ります。
403//!
404//! ```
405//! use fixed_record::prelude::*;
406//!
407//! #[fixed_record]
408//! struct Order {
409//! customer_id: Fixed<4>,
410//! order_no: Fixed<6>,
411//! amount: Fixed<8>,
412//! }
413//!
414//! let mut list = OrderList::new();
415//! list.push(Order::builder().with_customer_id("C001").with_order_no("A00001").with_amount_int(100).build());
416//! list.push(Order::builder().with_customer_id("C001").with_order_no("A00002").with_amount_int(200).build());
417//! list.push(Order::builder().with_customer_id("C001").with_order_no("A00003").with_amount_int(300).build());
418//!
419//! let found = list
420//! .try_find_range_by(OrderField::Amount, b"00000150"..=b"00000300")
421//! .unwrap();
422//!
423//! assert_eq!(found.len(), 2);
424//! assert_eq!(found[0].amount(), b"00000200");
425//! assert_eq!(found[1].amount(), b"00000300");
426//! ```
427//!
428//! # Clear Byte and Initialization / clear_byte と初期化
429//!
430//! By default, [`macro@fixed_record`] uses spaces (`0x20`) as `CLEAR_BYTE`. You can change this with
431//! `clear_byte = ZERO`, `clear_byte = SPACE`, a byte literal, or an integer from `0` to `255`.
432//!
433//! 標準では [`macro@fixed_record`] は半角スペース (`0x20`) を `CLEAR_BYTE` として使います。
434//! `clear_byte = ZERO`、`clear_byte = SPACE`、byte literal、`0` から `255` の整数で変更できます。
435//!
436//! ```
437//! use fixed_record::prelude::*;
438//!
439//! #[fixed_record(clear_byte = ZERO)]
440//! struct ZeroPaddedName {
441//! name: Fixed<6>,
442//! }
443//!
444//! let mut record = ZeroPaddedName::builder().with_name("Alice").build();
445//! record.set_field_str(ZeroPaddedNameField::Name, "Bo");
446//!
447//! assert_eq!(ZeroPaddedName::CLEAR_BYTE, 0x00);
448//! assert_eq!(record.name(), b"Bo\0\0\0\0");
449//! assert_eq!(ZeroPaddedName::zeroed().name(), b"\0\0\0\0\0\0");
450//! assert_eq!(ZeroPaddedName::spaced().name(), b" ");
451//! assert_eq!(ZeroPaddedName::cleared().name(), b"\0\0\0\0\0\0");
452//! ```
453//!
454//! # FixedRecord Trait / FixedRecord trait
455//!
456//! Generated records implement [`FixedRecord`], so generic code can parse or serialize any generated
457//! record type accepted by [`Reader`] and [`Writer`].
458//!
459//! 生成されたレコードは [`FixedRecord`] を実装します。そのため [`Reader`] / [`Writer`] が扱える
460//! 任意の生成レコードに対して generic な parse / serialize 処理を書けます。
461//!
462//! ```
463//! use fixed_record::prelude::*;
464//!
465//! #[fixed_record]
466//! struct Order {
467//! customer_id: Fixed<4>,
468//! order_no: Fixed<6>,
469//! amount: Fixed<8>,
470//! }
471//!
472//! fn serialize<T: FixedRecord>(record: &T) -> Vec<u8> {
473//! record.to_bytes()
474//! }
475//!
476//! let order = Order::builder()
477//! .with_customer_id("C001")
478//! .with_order_no("A00042")
479//! .with_amount_int(1250)
480//! .build();
481//!
482//! assert_eq!(serialize(&order), b"C001A0004200001250");
483//! ```
484//!
485//! # Feature Flags / feature flag
486//!
487//! - `list`: enabled by default. Generates the optional `{StructName}List` helper.
488//! - `list`: default で有効です。補助機能の `{StructName}List` を生成します。
489//!
490//! Disable default features when you only need records, field operations, parsing, `Reader`, and
491//! `Writer`:
492//!
493//! レコード本体、フィールド操作、parse、`Reader`、`Writer` だけを使う場合:
494//!
495//! ```toml
496//! [dependencies]
497//! fixed-record = { version = "0.1", default-features = false }
498//! ```
499//!
500//! # Zerocopy Support / zerocopy 対応
501//!
502//! Generated records always use `#[repr(C)]` and derive `zerocopy::FromBytes`,
503//! `zerocopy::IntoBytes`, `zerocopy::Immutable`, and `zerocopy::KnownLayout`.
504//! The zerocopy traits are re-exported from [`prelude`].
505//!
506//! 生成レコードには常に `#[repr(C)]` が付き、`zerocopy::FromBytes`、
507//! `zerocopy::IntoBytes`、`zerocopy::Immutable`、`zerocopy::KnownLayout` を derive します。
508//! zerocopy traits は [`prelude`] から再エクスポートされます。
509//!
510//! ```
511//! use fixed_record::prelude::*;
512//!
513//! #[fixed_record]
514//! struct Order {
515//! customer_id: Fixed<4>,
516//! order_no: Fixed<6>,
517//! amount: Fixed<8>,
518//! }
519//!
520//! let raw = b"C001A0004200001250";
521//!
522//! let order = Order::ref_from_bytes(raw).unwrap();
523//! assert_eq!(order.customer_id(), b"C001");
524//! assert_eq!(order.as_bytes(), raw);
525//! assert_eq!(order.as_str().unwrap(), "C001A0004200001250");
526//! ```
527//!
528//! Use `ref_from_bytes_prefix` when the input may contain trailing bytes after the first record.
529//!
530//! 先頭1レコードの後ろに余りバイトが続く可能性がある場合は、`ref_from_bytes_prefix` を使います。
531//!
532//! ```
533//! use fixed_record::prelude::*;
534//!
535//! #[fixed_record]
536//! struct Order {
537//! customer_id: Fixed<4>,
538//! order_no: Fixed<6>,
539//! amount: Fixed<8>,
540//! }
541//!
542//! let raw = b"C001A0004200001250rest";
543//! let order = Order::ref_from_bytes_prefix(raw).unwrap();
544//! assert_eq!(order.customer_id(), b"C001");
545//! ```
546//!
547//! String inputs can use `ref_from_str` or `ref_from_str_prefix`.
548//!
549//! 文字列入力では `ref_from_str` または `ref_from_str_prefix` を使えます。
550//!
551//! ```
552//! use fixed_record::prelude::*;
553//!
554//! #[fixed_record]
555//! struct Order {
556//! customer_id: Fixed<4>,
557//! order_no: Fixed<6>,
558//! amount: Fixed<8>,
559//! }
560//!
561//! let order = Order::ref_from_str_prefix("C001A0004200001250rest").unwrap();
562//! assert_eq!(order.order_no_str().unwrap(), "A00042");
563//! ```
564//!
565extern crate self as fixed_record;
566
567pub mod error;
568pub mod io;
569pub mod traits;
570pub mod types;
571
572pub use fixed_record_macros::fixed_record;
573pub use zerocopy;
574
575pub use error::Error;
576pub use io::{Reader, RecordSeparator, Writer};
577#[cfg(feature = "list")]
578pub use traits::RecordWithList;
579pub use traits::{ByteRangeBounds, FixedRecord};
580pub use types::Fixed;
581pub use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
582
583pub mod prelude {
584 #[cfg(feature = "list")]
585 pub use crate::RecordWithList;
586 pub use crate::fixed_record;
587 pub use crate::{
588 ByteRangeBounds, Error, Fixed, FixedRecord, FromBytes, Immutable, IntoBytes, KnownLayout,
589 Reader, RecordSeparator, Writer,
590 };
591}
592
593/// Documentation examples for APIs generated by [`macro@fixed_record`].
594/// [`macro@fixed_record`] が生成する API を rustdoc で確認するためのサンプルです。
595#[cfg(doc)]
596pub mod doc_examples {
597 use crate::prelude::*;
598
599 /// Test record used to document the generated fixed-record API.
600 /// 生成される fixed-record API のドキュメント用テストレコードです。
601 #[fixed_record]
602 pub struct TestRecord {
603 /// Name field used by generated API tests.
604 /// 生成 API テストで使う名前フィールドです。
605 name: Fixed<10>,
606 /// Code field used by generated API tests.
607 /// 生成 API テストで使うコードフィールドです。
608 code: Fixed<5>,
609 /// Amount field used by generated API tests.
610 /// 生成 API テストで使う金額フィールドです。
611 amount: Fixed<8>,
612 }
613}