Skip to main content

ThingBuilder

Struct ThingBuilder 

Source
pub struct ThingBuilder { /* private fields */ }
Expand description

Fluent builder for Thing.

All string setters accept impl Into<String> so call-sites may pass &str, String, or &String interchangeably without explicit conversion.

§Example

use thing_matcher::{Thing, ThingBuilder};

let t: Thing = ThingBuilder::default()
    .name(String::from("Eiffel Tower"))
    .add_alternate_name("La Tour Eiffel")
    .url("https://www.toureiffel.paris/")
    .add_same_as("https://www.wikidata.org/wiki/Q243")
    .build();

assert_eq!(t.name.as_deref(), Some("Eiffel Tower"));
assert_eq!(t.same_as.len(), 1);

Implementations§

Source§

impl ThingBuilder

Source

pub fn name<S: Into<String>>(self, value: S) -> Self

Set the primary canonical name.

let t = Thing::builder().name("Eiffel Tower").build();
assert_eq!(t.name.as_deref(), Some("Eiffel Tower"));
Source

pub fn alternate_names(self, value: Vec<String>) -> Self

Replace the entire list of alternate names.

let t = Thing::builder()
    .alternate_names(vec!["La Tour Eiffel".into(), "Tour Eiffel".into()])
    .build();
assert_eq!(t.alternate_names.len(), 2);
Source

pub fn add_alternate_name<S: Into<String>>(self, value: S) -> Self

Append a single alternate name.

let t = Thing::builder()
    .add_alternate_name("La Tour Eiffel")
    .add_alternate_name("Tour Eiffel")
    .build();
assert_eq!(t.alternate_names.len(), 2);
Source

pub fn description<S: Into<String>>(self, value: S) -> Self

Set the free-form description.

let t = Thing::builder().description("A landmark in Paris.").build();
assert_eq!(t.description.as_deref(), Some("A landmark in Paris."));
Source

pub fn disambiguating_description<S: Into<String>>(self, value: S) -> Self

Set the disambiguating description.

let t = Thing::builder().disambiguating_description("The Paris one.").build();
assert_eq!(t.disambiguating_description.as_deref(), Some("The Paris one."));
Source

pub fn identifiers(self, value: Vec<Identifier>) -> Self

Replace the entire list of identifiers.

let id = Identifier::new("wikidata", "Q243").unwrap();
let t = Thing::builder().identifiers(vec![id.clone()]).build();
assert_eq!(t.identifiers, vec![id]);
Source

pub fn add_identifier(self, value: Identifier) -> Self

Append a single identifier.

let t = Thing::builder()
    .add_identifier(Identifier::new("wikidata", "Q243").unwrap())
    .build();
assert_eq!(t.identifiers.len(), 1);
Source

pub fn url<S: Into<String>>(self, value: S) -> Self

Set the canonical URL.

let t = Thing::builder().url("https://www.toureiffel.paris/").build();
assert_eq!(t.url.as_deref(), Some("https://www.toureiffel.paris/"));
Source

pub fn image<S: Into<String>>(self, value: S) -> Self

Set the representative image URL.

let t = Thing::builder().image("https://example.org/eiffel.jpg").build();
assert_eq!(t.image.as_deref(), Some("https://example.org/eiffel.jpg"));
Source

pub fn same_as(self, value: Vec<String>) -> Self

Replace the entire sameAs list.

let t = Thing::builder()
    .same_as(vec![
        "https://www.wikidata.org/wiki/Q243".into(),
        "https://en.wikipedia.org/wiki/Eiffel_Tower".into(),
    ])
    .build();
assert_eq!(t.same_as.len(), 2);
Source

pub fn add_same_as<S: Into<String>>(self, value: S) -> Self

Append a single sameAs URL.

let t = Thing::builder()
    .add_same_as("https://www.wikidata.org/wiki/Q243")
    .build();
assert_eq!(t.same_as.len(), 1);
Source

pub fn main_entity_of_page<S: Into<String>>(self, value: S) -> Self

Set the mainEntityOfPage URL.

let t = Thing::builder()
    .main_entity_of_page("https://en.wikipedia.org/wiki/Eiffel_Tower")
    .build();
assert_eq!(
    t.main_entity_of_page.as_deref(),
    Some("https://en.wikipedia.org/wiki/Eiffel_Tower"),
);
Source

pub fn additional_types(self, value: Vec<String>) -> Self

Replace the entire list of additionalType URIs.

let t = Thing::builder()
    .additional_types(vec!["https://schema.org/Landmark".into()])
    .build();
assert_eq!(t.additional_types.len(), 1);
Source

pub fn add_additional_type<S: Into<String>>(self, value: S) -> Self

Append a single additionalType URI.

let t = Thing::builder()
    .add_additional_type("https://schema.org/Landmark")
    .build();
assert_eq!(t.additional_types.len(), 1);
Source

pub fn subject_of(self, value: Vec<String>) -> Self

Replace the entire subjectOf list.

Source

pub fn add_subject_of<S: Into<String>>(self, value: S) -> Self

Append a single subjectOf URL.

Source

pub fn owner<S: Into<String>>(self, value: S) -> Self

Set the owner (person or organisation, as a string).

Source

pub fn local_id<S: Into<String>>(self, value: S) -> Self

Set the local identifier.

let t = Thing::builder().local_id("REF-12345").build();
assert_eq!(t.local_id.as_deref(), Some("REF-12345"));
Source

pub fn build(self) -> Thing

Consume the builder and produce the Thing.

let t = Thing::builder().name("Big Ben").build();
assert!(t.url.is_none());

Trait Implementations§

Source§

impl Default for ThingBuilder

Source§

fn default() -> ThingBuilder

Returns the “default value” for a type. 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> 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, 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.