Skip to main content

TestRecordList

Struct TestRecordList 

Source
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

Source

pub fn new() -> Self

Creates an empty list. 空のリストを作成します。

Source

pub fn from_records(records: Vec<TestRecord>) -> Self

Creates a list from records in their current order and builds all field indexes. レコードの現在順からリストを作成し、全フィールド索引を構築します。

Source

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 から残りの全レコードを読み込み、フィールド索引を構築します。

Source

pub fn len(&self) -> usize

Returns the number of records. レコード数を返します。

Source

pub fn is_empty(&self) -> bool

Returns whether there are no records. レコードがないかを返します。

Source

pub fn clear(&mut self)

Removes all records and clears all field indexes. 全レコードを削除し、全フィールド索引を空にします。

Source

pub fn retain(&mut self, keep: impl FnMut(&TestRecord) -> bool)

👎Deprecated:

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 により索引を再構築します。

Source

pub fn iter<'a>(&'a self) -> impl Iterator<Item = &'a TestRecord> + 'a

Returns an iterator over records in the current order. 現在の順序でレコードを返すイテレータです。

Source

pub 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

Returns the first record matching the predicate by scanning in the current order. 現在の順序で走査し、predicate に一致する最初のレコードを返します。

Source

pub 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

Returns all records matching the predicate by scanning in the current order. 現在の順序で走査し、predicate に一致する全レコードを返します。

Source

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 により索引を再構築します。

Source

pub fn push(&mut self, record: TestRecord) -> usize

Appends a record and returns its current index as the ID. レコードを末尾へ追加し、現在の index を ID として返します。

Source

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 を返します。

Source

pub fn get(&self, id: usize) -> Option<&TestRecord>

Returns the record at the specified current index. 指定された現在の index にあるレコードを返します。

Source

pub fn update(&mut self, id: usize, record: TestRecord) -> bool

Replaces the record at the specified current index and updates all field indexes. 指定された現在の index にあるレコードを置き換え、全フィールド索引を更新します。

Source

pub fn remove(&mut self, id: usize) -> bool

Removes the record at the specified current index and updates shifted field indexes. 指定された現在の index にあるレコードを削除し、移動したフィールド索引を更新します。

Source

pub fn pop(&mut self) -> Option<TestRecord>

Removes and returns the last record without rebuilding the field indexes. フィールド索引を再構築せず、末尾のレコードを削除して返します。

Source

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 を返します。

Source

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 を返します。

Source

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 を返します。

Source

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 を返します。

Source

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. 指定フィールドの索引上の昇順でレコードを返すイテレータです。

Source

pub fn sort(&mut self)

Sorts records by comparing all fields in declaration order and rebuilds the indexes. レコードを定義順の全フィールド比較でソートし、索引を再構築します。

Source

pub fn sort_by(&mut self, fields: &[TestRecordField])

Sorts records by the specified field priority order and rebuilds the indexes. 指定したフィールド優先順でレコードをソートし、索引を再構築します。

Source

pub fn first(&self) -> Option<&TestRecord>

Returns the first record in the current order. 現在の順序で最初のレコードを返します。

Source

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 を返します。

Source

pub fn first_sorted_by(&self, field: TestRecordField) -> Option<&TestRecord>

Returns the first record in indexed ascending order by the specified field. 指定フィールドの索引上の昇順で最初のレコードを返します。

Source

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 を返します。

Source

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 を返します。

Source

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 を公開せず、変更したレコード数を返します。

Source

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 を公開せず、変更したレコード数を返します。

Source

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 を公開せず、変更したレコード数を返します。

Source

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 を公開せず、変更したレコード数を返します。

Source

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 を公開せず、レコードを変更したかを返します。

Source

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 を公開せず、レコードを変更したかを返します。

Source

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 を公開せず、レコードを変更したかを返します。

Source

pub fn all_ids(&self) -> Vec<usize>

Returns all current record IDs. 現在の全レコード ID を返します。

Trait Implementations§

Source§

impl Default for TestRecordList

Source§

fn default() -> Self

Creates an empty list. 空のリストを作成します。

Source§

impl From<Vec<TestRecord>> for TestRecordList

Source§

fn from(records: Vec<TestRecord>) -> Self

Creates a list from a vector of records. レコードの vector からリストを作成します。

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.