Skip to main content

Record

Struct Record 

Source
#[non_exhaustive]
pub struct Record { pub raw: Value, pub score: Option<f64>, }
Expand description

One concrete record passed into clustering.

raw is the original parsed item (never mutated). score is the result of resolving the optional score path against raw and converting to f64. None when no score was configured for this run, or when the score path didn’t resolve to a number for this particular record.

Record is #[non_exhaustive] — construct values via Record::new or Record::from_items.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§raw: Value

Original parsed item, never mutated.

§score: Option<f64>

Resolved score, when a score path was configured and the value at that path was a JSON number.

Implementations§

Source§

impl Record

Source

pub fn new(raw: Value) -> Self

Construct a record with no score resolved.

§Examples
use face_core::Record;
use serde_json::json;

let r = Record::new(json!({"score": 0.9}));
assert!(r.score.is_none());
Source

pub fn from_items(items: Vec<Value>, score_path: Option<&str>) -> Vec<Record>

Build a Vec<Record> from a parsed items list.

When score_path is None, all records have score: None. When score_path is Some(path), the path is resolved against each record. If the resolved value is a JSON number, it becomes the record’s score. Otherwise the score remains None (this is per-record permissiveness — strategies decide whether missing scores are a problem).

--invert polarity flipping is the caller’s responsibility: pass already-inverted scores via a follow-up apply_invert, or build records via from_items and let the caller iterate. Slice 5 does not auto-invert.

§Examples
use face_core::Record;
use serde_json::json;

let items = vec![
    json!({"score": 0.9}),
    json!({"score": "n/a"}),
];
let records = Record::from_items(items, Some("score"));
assert_eq!(records[0].score, Some(0.9));
assert_eq!(records[1].score, None);

Trait Implementations§

Source§

impl Clone for Record

Source§

fn clone(&self) -> Record

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Record

Source§

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

Formats the value using the given formatter. Read more

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
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.