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
impl ThingBuilder
Sourcepub fn name<S: Into<String>>(self, value: S) -> Self
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"));Sourcepub fn alternate_names(self, value: Vec<String>) -> Self
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);Sourcepub fn add_alternate_name<S: Into<String>>(self, value: S) -> Self
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);Sourcepub fn description<S: Into<String>>(self, value: S) -> Self
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."));Sourcepub fn disambiguating_description<S: Into<String>>(self, value: S) -> Self
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."));Sourcepub fn identifiers(self, value: Vec<Identifier>) -> Self
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]);Sourcepub fn add_identifier(self, value: Identifier) -> Self
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);Sourcepub fn url<S: Into<String>>(self, value: S) -> Self
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/"));Sourcepub fn image<S: Into<String>>(self, value: S) -> Self
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"));Sourcepub fn same_as(self, value: Vec<String>) -> Self
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);Sourcepub fn add_same_as<S: Into<String>>(self, value: S) -> Self
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);Sourcepub fn main_entity_of_page<S: Into<String>>(self, value: S) -> Self
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"),
);Sourcepub fn additional_types(self, value: Vec<String>) -> Self
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);Sourcepub fn add_additional_type<S: Into<String>>(self, value: S) -> Self
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);Sourcepub fn subject_of(self, value: Vec<String>) -> Self
pub fn subject_of(self, value: Vec<String>) -> Self
Replace the entire subjectOf list.
Sourcepub fn add_subject_of<S: Into<String>>(self, value: S) -> Self
pub fn add_subject_of<S: Into<String>>(self, value: S) -> Self
Append a single subjectOf URL.
Sourcepub fn owner<S: Into<String>>(self, value: S) -> Self
pub fn owner<S: Into<String>>(self, value: S) -> Self
Set the owner (person or organisation, as a string).
Trait Implementations§
Source§impl Default for ThingBuilder
impl Default for ThingBuilder
Source§fn default() -> ThingBuilder
fn default() -> ThingBuilder
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for ThingBuilder
impl RefUnwindSafe for ThingBuilder
impl Send for ThingBuilder
impl Sync for ThingBuilder
impl Unpin for ThingBuilder
impl UnsafeUnpin for ThingBuilder
impl UnwindSafe for ThingBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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