Skip to main content

RankedItem

Struct RankedItem 

Source
pub struct RankedItem<'a, T> {
    pub item: &'a T,
    pub index: usize,
    pub rank: Ranking,
    pub ranked_value: Cow<'a, str>,
    pub key_index: usize,
    pub key_threshold: Option<Ranking>,
}
Expand description

An item annotated with its ranking information.

Produced during the ranking phase of the match-sorting pipeline and passed to sorting functions (both the default three-level comparator and custom base_sort / sorter overrides).

§Type Parameters

  • 'a - Lifetime of the reference to the original item in the input slice.
  • T - The item type being ranked.

§Examples

use std::borrow::Cow;
use matchsorter::{RankedItem, Ranking};

let item = "hello".to_owned();
let ranked = RankedItem {
    item: &item,
    index: 0,
    rank: Ranking::CaseSensitiveEqual,
    ranked_value: Cow::Borrowed("hello"),
    key_index: 0,
    key_threshold: None,
};
assert_eq!(ranked.rank, Ranking::CaseSensitiveEqual);
assert_eq!(*ranked.item, "hello");

Fields§

§item: &'a T

Reference to the original item in the input slice.

§index: usize

Original index of the item in the input slice, used for stable sort tie-breaking.

§rank: Ranking

The ranking score representing how well the item matched the query.

§ranked_value: Cow<'a, str>

The string value (from one of the item’s keys) that produced the best match against the query. Borrowed in no-keys mode (zero-copy from the input slice) and owned in keys mode.

§key_index: usize

Index of the winning key-value pair in the flattened key-values list. Lower values indicate keys declared earlier in the keys array.

§key_threshold: Option<Ranking>

Per-key threshold override from the winning key, or None if the key uses the global threshold.

Trait Implementations§

Source§

impl<'a, T: Clone> Clone for RankedItem<'a, T>

Source§

fn clone(&self) -> RankedItem<'a, T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a, T: Debug> Debug for RankedItem<'a, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, T: PartialEq> PartialEq for RankedItem<'a, T>

Source§

fn eq(&self, other: &RankedItem<'a, T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, T> StructuralPartialEq for RankedItem<'a, T>

Auto Trait Implementations§

§

impl<'a, T> Freeze for RankedItem<'a, T>

§

impl<'a, T> RefUnwindSafe for RankedItem<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Send for RankedItem<'a, T>
where T: Sync,

§

impl<'a, T> Sync for RankedItem<'a, T>
where T: Sync,

§

impl<'a, T> Unpin for RankedItem<'a, T>

§

impl<'a, T> UnsafeUnpin for RankedItem<'a, T>

§

impl<'a, T> UnwindSafe for RankedItem<'a, T>
where T: RefUnwindSafe,

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
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.