Skip to main content

Thing

Struct Thing 

Source
#[non_exhaustive]
pub struct Thing {
Show 13 fields pub name: Option<String>, pub alternate_names: Vec<String>, pub description: Option<String>, pub disambiguating_description: Option<String>, pub identifiers: Vec<Identifier>, pub url: Option<String>, pub image: Option<String>, pub same_as: Vec<String>, pub main_entity_of_page: Option<String>, pub additional_types: Vec<String>, pub subject_of: Vec<String>, pub owner: Option<String>, pub local_id: Option<String>,
}
Expand description

Core data structure for a thing, aligned with schema.org/Thing.

Every field is optional (or defaults to empty). The matcher tolerates missing data field-by-field — a None value never penalises a thing. See crate::matcher::MatchingEngine::match_things for how missing fields affect the weighted score.

Construct via Thing::builder rather than struct literal syntax so the call-site stays compact and forward-compatible if fields are added.

§Example

use thing_matcher::Thing;

let t = Thing::builder()
    .name("Eiffel Tower")
    .add_alternate_name("La Tour Eiffel")
    .description("Wrought-iron lattice tower on the Champ de Mars in Paris.")
    .url("https://www.toureiffel.paris/")
    .build();

assert_eq!(t.name.as_deref(), Some("Eiffel Tower"));
assert_eq!(t.alternate_names, vec!["La Tour Eiffel".to_string()]);

Thing round-trips through serde.

let t = Thing::builder().name("Eiffel Tower").build();
let json = serde_json::to_string(&t).unwrap();
let back: Thing = serde_json::from_str(&json).unwrap();
assert_eq!(t, back);

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.
§name: Option<String>

Primary canonical name. Corresponds to schema.org/name.

§alternate_names: Vec<String>

Aliases, endonyms, or translations. Corresponds to schema.org/alternateName. The matcher takes the best score across the cartesian product of primary + alternates.

§description: Option<String>

Free-form description. Corresponds to schema.org/description.

§disambiguating_description: Option<String>

Short disambiguating description. Corresponds to schema.org/disambiguatingDescription.

§identifiers: Vec<Identifier>

Scheme-scoped external identifiers. Corresponds to schema.org/identifier modelled as PropertyValue. Sharing any one (property_id, value) pair across two things is a deterministic match.

§url: Option<String>

Canonical URL of the item. Corresponds to schema.org/url.

§image: Option<String>

URL of a representative image. Corresponds to schema.org/image.

§same_as: Vec<String>

Reference URLs that unambiguously indicate the same item, e.g. a Wikipedia article or an authority record. Corresponds to schema.org/sameAs.

§main_entity_of_page: Option<String>

Page (URL) for which this thing is the main entity. Corresponds to schema.org/mainEntityOfPage.

§additional_types: Vec<String>

Additional types from external vocabularies, typically schema.org subtypes or other ontology URIs. Corresponds to schema.org/additionalType.

§subject_of: Vec<String>

Works or events about this thing (URLs). Corresponds to schema.org/subjectOf.

§owner: Option<String>

Person or organisation that owns this thing. Corresponds to schema.org/owner. Stored as a string (a name or URL) — the crate does not model Person / Organization separately.

§local_id: Option<String>

Local identifier issued by the originating system. Not normalised, not scored — different organisations may issue colliding values. Kept for round-trip honesty.

Implementations§

Source§

impl Thing

Source

pub fn builder() -> ThingBuilder

Begin constructing a Thing with the ThingBuilder.

All fields default to None / empty until a setter is called.

§Example
use thing_matcher::Thing;

let t = Thing::builder()
    .name("Big Ben")
    .build();

assert_eq!(t.name.as_deref(), Some("Big Ben"));
Source

pub fn validate(&self) -> Result<()>

Validate that the thing carries a primary name.

Returns Ok(()) if name is set. Otherwise returns crate::MatchingError::MissingField.

This is not invoked automatically by the matcher — call it at the system boundary when you ingest data, not on every comparison.

§Example
use thing_matcher::Thing;

assert!(Thing::builder().name("Eiffel Tower").build().validate().is_ok());
assert!(Thing::builder().build().validate().is_err());

Trait Implementations§

Source§

impl Clone for Thing

Source§

fn clone(&self) -> Thing

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 Thing

Source§

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

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

impl Default for Thing

Source§

fn default() -> Thing

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Thing

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Thing

Source§

fn eq(&self, other: &Thing) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 Serialize for Thing

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Thing

Source§

impl StructuralPartialEq for Thing

Auto Trait Implementations§

§

impl Freeze for Thing

§

impl RefUnwindSafe for Thing

§

impl Send for Thing

§

impl Sync for Thing

§

impl Unpin for Thing

§

impl UnsafeUnpin for Thing

§

impl UnwindSafe for Thing

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,