pub struct TestRecordList { /* private fields */ }Expand description
Stores boxed records in a vector and maintains field indexes for search and sorting. Box 化したレコードを vector に保持し、検索・ソート用のフィールド索引を管理します。 Each field index maps actual field bytes to the current vector indexes of matching records. 各フィールド索引は、実際のフィールドバイト列から、一致するレコードの現在の vector index へ対応付けます。 Sorting moves boxes in the vector, not the record values allocated behind them. ソート時は vector 内の Box が移動し、Box の先にあるレコード本体は移動しません。 Record IDs are the current vector indexes, so IDs can change after removal or sorting. レコード ID は現在の vector index です。そのため削除やソート後に ID は変わる可能性があります。
Implementations§
Source§impl TestRecordList
impl TestRecordList
Sourcepub fn from_records(records: Vec<TestRecord>) -> Self
pub fn from_records(records: Vec<TestRecord>) -> Self
Creates a list from records in their current order and builds all field indexes. レコードの現在順からリストを作成し、全フィールド索引を構築します。
Sourcepub fn read_from<R: BufRead>(
reader: Reader<R, TestRecord>,
) -> Result<Self, Error>
pub fn read_from<R: BufRead>( reader: Reader<R, TestRecord>, ) -> Result<Self, Error>
Reads all remaining records from a configured Reader and builds their field indexes. 設定済み Reader から残りの全レコードを読み込み、フィールド索引を構築します。
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Removes all records and clears all field indexes. 全レコードを削除し、全フィールド索引を空にします。
Sourcepub fn retain(&mut self, keep: impl FnMut(&TestRecord) -> bool)
👎Deprecated: performs a linear scan and rebuilds all field indexes; prefer indexed operations
pub fn retain(&mut self, keep: impl FnMut(&TestRecord) -> bool)
performs a linear scan and rebuilds all field indexes; prefer indexed operations
Retains only records for which the predicate returns true and rebuilds all field indexes.
predicate が true を返すレコードだけを残し、全フィールド索引を再構築します。
Indexes are rebuilt by a drop guard even if the predicate unwinds.
predicate が unwind した場合も drop guard により索引を再構築します。
Sourcepub fn iter<'a>(&'a self) -> impl Iterator<Item = &'a TestRecord> + 'a
pub fn iter<'a>(&'a self) -> impl Iterator<Item = &'a TestRecord> + 'a
Returns an iterator over records in the current order. 現在の順序でレコードを返すイテレータです。
Sourcepub fn find(
&self,
predicate: impl FnMut(&TestRecord) -> bool,
) -> Option<&TestRecord>
👎Deprecated: performs a linear scan; use try_first_by*, first_sorted_by, or another indexed lookup
pub fn find( &self, predicate: impl FnMut(&TestRecord) -> bool, ) -> Option<&TestRecord>
performs a linear scan; use try_first_by*, first_sorted_by, or another indexed lookup
Returns the first record matching the predicate by scanning in the current order. 現在の順序で走査し、predicate に一致する最初のレコードを返します。
Sourcepub fn find_all(
&self,
predicate: impl FnMut(&TestRecord) -> bool,
) -> Vec<&TestRecord>
👎Deprecated: performs a linear scan; use try_find_by*, try_find_range_by, or another indexed lookup
pub fn find_all( &self, predicate: impl FnMut(&TestRecord) -> bool, ) -> Vec<&TestRecord>
performs a linear scan; use try_find_by*, try_find_range_by, or another indexed lookup
Returns all records matching the predicate by scanning in the current order. 現在の順序で走査し、predicate に一致する全レコードを返します。
Sourcepub fn for_each_mut(&mut self, edit: impl FnMut(&mut TestRecord))
pub fn for_each_mut(&mut self, edit: impl FnMut(&mut TestRecord))
Mutates every record in the current order and rebuilds all field indexes afterward. 現在の順序で全レコードを変更し、処理後に全フィールド索引を再構築します。 Mutable record references are confined to the callback and cannot be retained by the caller. レコードの mutable 参照は callback 内に限定され、呼び出し側では保持できません。 Indexes are rebuilt by a drop guard even if the callback unwinds. callback が unwind した場合も drop guard により索引を再構築します。
Sourcepub fn push(&mut self, record: TestRecord) -> usize
pub fn push(&mut self, record: TestRecord) -> usize
Appends a record and returns its current index as the ID. レコードを末尾へ追加し、現在の index を ID として返します。
Sourcepub fn insert(&mut self, index: usize, record: TestRecord) -> bool
pub fn insert(&mut self, index: usize, record: TestRecord) -> bool
Inserts a record at the specified index and updates shifted field indexes.
指定 index にレコードを挿入し、移動したフィールド索引を更新します。
Returns false without changing the list when index is greater than len().
index が len() より大きい場合は List を変更せず false を返します。
Sourcepub fn get(&self, id: usize) -> Option<&TestRecord>
pub fn get(&self, id: usize) -> Option<&TestRecord>
Returns the record at the specified current index. 指定された現在の index にあるレコードを返します。
Sourcepub fn update(&mut self, id: usize, record: TestRecord) -> bool
pub fn update(&mut self, id: usize, record: TestRecord) -> bool
Replaces the record at the specified current index and updates all field indexes. 指定された現在の index にあるレコードを置き換え、全フィールド索引を更新します。
Sourcepub fn remove(&mut self, id: usize) -> bool
pub fn remove(&mut self, id: usize) -> bool
Removes the record at the specified current index and updates shifted field indexes. 指定された現在の index にあるレコードを削除し、移動したフィールド索引を更新します。
Sourcepub fn pop(&mut self) -> Option<TestRecord>
pub fn pop(&mut self) -> Option<TestRecord>
Removes and returns the last record without rebuilding the field indexes. フィールド索引を再構築せず、末尾のレコードを削除して返します。
Sourcepub fn try_find_by(
&self,
field: TestRecordField,
value: impl AsRef<[u8]>,
) -> Result<Vec<&TestRecord>, Error>
pub fn try_find_by( &self, field: TestRecordField, value: impl AsRef<[u8]>, ) -> Result<Vec<&TestRecord>, Error>
Returns records whose specified field exactly matches the value using the field index.
フィールド索引を使い、指定フィールドが値と完全一致するレコードを返します。
Returns Error::TooShort when the search value is shorter than the field.
検索値がフィールド幅より短い場合は Error::TooShort を返します。
Returns Error::FieldOverflow when the search value is wider than the field.
検索値がフィールド幅を超える場合は Error::FieldOverflow を返します。
Sourcepub fn try_find_by_padded(
&self,
field: TestRecordField,
value: impl AsRef<[u8]>,
) -> Result<Vec<&TestRecord>, Error>
pub fn try_find_by_padded( &self, field: TestRecordField, value: impl AsRef<[u8]>, ) -> Result<Vec<&TestRecord>, Error>
Returns records whose specified field matches a possibly shortened padded value.
指定フィールドが、短縮可能な padding 付きの値と一致するレコードを返します。
When the search value is shorter than the field width, trailing 0x00 or space bytes are accepted.
検索値がフィールド幅より短い場合は、後続バイトが 0x00 または半角スペースのレコードも一致します。
Returns Error::FieldOverflow when the search value is wider than the field.
検索値がフィールド幅を超える場合は Error::FieldOverflow を返します。
Sourcepub fn try_find_by_prefix(
&self,
field: TestRecordField,
value: impl AsRef<[u8]>,
) -> Result<Vec<&TestRecord>, Error>
pub fn try_find_by_prefix( &self, field: TestRecordField, value: impl AsRef<[u8]>, ) -> Result<Vec<&TestRecord>, Error>
Returns records whose specified field starts with the value using the field index.
フィールド索引を使い、指定フィールドが値で始まるレコードを返します。
When the search value is shorter than the field width, trailing bytes may contain any value.
検索値がフィールド幅より短い場合は、後続バイトの内容に関係なく一致します。
Returns Error::FieldOverflow when the search value is wider than the field.
検索値がフィールド幅を超える場合は Error::FieldOverflow を返します。
Sourcepub fn try_find_range_by<R>(
&self,
field: TestRecordField,
range: R,
) -> Result<Vec<&TestRecord>, Error>where
R: ByteRangeBounds,
pub fn try_find_range_by<R>(
&self,
field: TestRecordField,
range: R,
) -> Result<Vec<&TestRecord>, Error>where
R: ByteRangeBounds,
Returns records whose specified field value is within the indexed range.
指定フィールドの値が索引上の範囲内にあるレコードを返します。
Short bounds allow any trailing field bytes.
短い境界値では、フィールドの後続バイトを任意として扱います。
Returns Error::FieldOverflow when either bound is wider than the field.
いずれかの境界値がフィールド幅を超える場合は Error::FieldOverflow を返します。
Returns Error::InvalidRange when the start value is greater than the end value.
開始値が終了値より大きい場合は Error::InvalidRange を返します。
Sourcepub fn iter_sorted_by<'a, const N: usize>(
&'a self,
field: TestRecordField,
) -> impl Iterator<Item = &'a TestRecord> + 'a
pub fn iter_sorted_by<'a, const N: usize>( &'a self, field: TestRecordField, ) -> impl Iterator<Item = &'a TestRecord> + 'a
Returns an iterator over records in indexed ascending order by the specified field. 指定フィールドの索引上の昇順でレコードを返すイテレータです。
Sourcepub fn sort(&mut self)
pub fn sort(&mut self)
Sorts records by comparing all fields in declaration order and rebuilds the indexes. レコードを定義順の全フィールド比較でソートし、索引を再構築します。
Sourcepub fn sort_by(&mut self, fields: &[TestRecordField])
pub fn sort_by(&mut self, fields: &[TestRecordField])
Sorts records by the specified field priority order and rebuilds the indexes. 指定したフィールド優先順でレコードをソートし、索引を再構築します。
Sourcepub fn first(&self) -> Option<&TestRecord>
pub fn first(&self) -> Option<&TestRecord>
Returns the first record in the current order. 現在の順序で最初のレコードを返します。
Sourcepub fn try_first_by(
&self,
field: TestRecordField,
value: impl AsRef<[u8]>,
) -> Result<Option<&TestRecord>, Error>
pub fn try_first_by( &self, field: TestRecordField, value: impl AsRef<[u8]>, ) -> Result<Option<&TestRecord>, Error>
Returns the first record whose specified field exactly matches the value.
指定フィールドが値と完全一致する最初のレコードを返します。
Returns Error::TooShort when the search value is shorter than the field.
検索値がフィールド幅より短い場合は Error::TooShort を返します。
Returns Error::FieldOverflow when the search value is wider than the field.
検索値がフィールド幅を超える場合は Error::FieldOverflow を返します。
Sourcepub fn first_sorted_by(&self, field: TestRecordField) -> Option<&TestRecord>
pub fn first_sorted_by(&self, field: TestRecordField) -> Option<&TestRecord>
Returns the first record in indexed ascending order by the specified field. 指定フィールドの索引上の昇順で最初のレコードを返します。
Sourcepub fn try_first_by_padded(
&self,
field: TestRecordField,
value: impl AsRef<[u8]>,
) -> Result<Option<&TestRecord>, Error>
pub fn try_first_by_padded( &self, field: TestRecordField, value: impl AsRef<[u8]>, ) -> Result<Option<&TestRecord>, Error>
Returns the first indexed record matching a possibly shortened padded value.
短縮可能な padding 付きの値と一致する、索引上で最初のレコードを返します。
When the search value is shorter than the field width, trailing 0x00 or space bytes are accepted.
検索値がフィールド幅より短い場合は、後続バイトが 0x00 または半角スペースのレコードも一致します。
Returns Error::FieldOverflow when the search value is wider than the field.
検索値がフィールド幅を超える場合は Error::FieldOverflow を返します。
Sourcepub fn try_first_by_prefix(
&self,
field: TestRecordField,
value: impl AsRef<[u8]>,
) -> Result<Option<&TestRecord>, Error>
pub fn try_first_by_prefix( &self, field: TestRecordField, value: impl AsRef<[u8]>, ) -> Result<Option<&TestRecord>, Error>
Returns the first indexed prefix match for the specified field.
指定フィールドが値で始まるレコードのうち、索引上で最初のものを返します。
Returns Error::FieldOverflow when the search value is wider than the field.
検索値がフィールド幅を超える場合は Error::FieldOverflow を返します。
Sourcepub fn try_edit_by(
&mut self,
field: TestRecordField,
value: impl AsRef<[u8]>,
edit: impl FnMut(&mut TestRecord),
) -> Result<usize, Error>
pub fn try_edit_by( &mut self, field: TestRecordField, value: impl AsRef<[u8]>, edit: impl FnMut(&mut TestRecord), ) -> Result<usize, Error>
Mutates every record whose specified field exactly matches the value. 指定フィールドが値と完全一致する全レコードを変更します。 Returns the number of edited records without exposing their internal current indexes. 内部の現在 index を公開せず、変更したレコード数を返します。
Sourcepub fn try_edit_by_padded(
&mut self,
field: TestRecordField,
value: impl AsRef<[u8]>,
edit: impl FnMut(&mut TestRecord),
) -> Result<usize, Error>
pub fn try_edit_by_padded( &mut self, field: TestRecordField, value: impl AsRef<[u8]>, edit: impl FnMut(&mut TestRecord), ) -> Result<usize, Error>
Mutates every record matching a possibly shortened padded field value. 短縮可能な padding 付きフィールド値に一致する全レコードを変更します。 Returns the number of edited records without exposing their internal current indexes. 内部の現在 index を公開せず、変更したレコード数を返します。
Sourcepub fn try_edit_by_prefix(
&mut self,
field: TestRecordField,
value: impl AsRef<[u8]>,
edit: impl FnMut(&mut TestRecord),
) -> Result<usize, Error>
pub fn try_edit_by_prefix( &mut self, field: TestRecordField, value: impl AsRef<[u8]>, edit: impl FnMut(&mut TestRecord), ) -> Result<usize, Error>
Mutates every record whose specified field starts with the value. 指定フィールドが値で始まる全レコードを変更します。 Returns the number of edited records without exposing their internal current indexes. 内部の現在 index を公開せず、変更したレコード数を返します。
Sourcepub fn try_edit_range_by<R>(
&mut self,
field: TestRecordField,
range: R,
edit: impl FnMut(&mut TestRecord),
) -> Result<usize, Error>where
R: ByteRangeBounds,
pub fn try_edit_range_by<R>(
&mut self,
field: TestRecordField,
range: R,
edit: impl FnMut(&mut TestRecord),
) -> Result<usize, Error>where
R: ByteRangeBounds,
Mutates every record whose specified field value is within the indexed range. 指定フィールドの値が索引上の範囲内にある全レコードを変更します。 Returns the number of edited records without exposing their internal current indexes. 内部の現在 index を公開せず、変更したレコード数を返します。
Sourcepub fn try_edit_first_by(
&mut self,
field: TestRecordField,
value: impl AsRef<[u8]>,
edit: impl FnOnce(&mut TestRecord),
) -> Result<bool, Error>
pub fn try_edit_first_by( &mut self, field: TestRecordField, value: impl AsRef<[u8]>, edit: impl FnOnce(&mut TestRecord), ) -> Result<bool, Error>
Mutates the first record whose specified field exactly matches the value. 指定フィールドが値と完全一致する最初のレコードを変更します。 Returns whether a record was edited without exposing its internal current index. 内部の現在 index を公開せず、レコードを変更したかを返します。
Sourcepub fn try_edit_first_by_padded(
&mut self,
field: TestRecordField,
value: impl AsRef<[u8]>,
edit: impl FnOnce(&mut TestRecord),
) -> Result<bool, Error>
pub fn try_edit_first_by_padded( &mut self, field: TestRecordField, value: impl AsRef<[u8]>, edit: impl FnOnce(&mut TestRecord), ) -> Result<bool, Error>
Mutates the first record matching a possibly shortened padded field value. 短縮可能な padding 付きフィールド値に一致する最初のレコードを変更します。 Returns whether a record was edited without exposing its internal current index. 内部の現在 index を公開せず、レコードを変更したかを返します。
Sourcepub fn try_edit_first_by_prefix(
&mut self,
field: TestRecordField,
value: impl AsRef<[u8]>,
edit: impl FnOnce(&mut TestRecord),
) -> Result<bool, Error>
pub fn try_edit_first_by_prefix( &mut self, field: TestRecordField, value: impl AsRef<[u8]>, edit: impl FnOnce(&mut TestRecord), ) -> Result<bool, Error>
Mutates the first record whose specified field starts with the value. 指定フィールドが値で始まる最初のレコードを変更します。 Returns whether a record was edited without exposing its internal current index. 内部の現在 index を公開せず、レコードを変更したかを返します。
Trait Implementations§
Source§impl Default for TestRecordList
impl Default for TestRecordList
Source§impl From<Vec<TestRecord>> for TestRecordList
impl From<Vec<TestRecord>> for TestRecordList
Source§fn from(records: Vec<TestRecord>) -> Self
fn from(records: Vec<TestRecord>) -> Self
Creates a list from a vector of records. レコードの vector からリストを作成します。