pub struct BaseThing { /* private fields */ }
Expand description
Basic web thing implementation.
This can easily be used by other things to handle most of the boring work.
Implementations
sourceimpl BaseThing
impl BaseThing
sourcepub fn new(
id: String,
title: String,
type_: Option<Vec<String>>,
description: Option<String>
) -> Self
pub fn new(
id: String,
title: String,
type_: Option<Vec<String>>,
description: Option<String>
) -> Self
Create a new BaseThing.
Arguments
id
- the thing’s unique ID - must be a URItitle
- the thing’s titletype_
- the thing’s type(s)description
- description of the thingcontext
- vocabularies to be used in the thing description
sourcepub fn with_context(self, context: ThingContext) -> Self
pub fn with_context(self, context: ThingContext) -> Self
Overwrite the Thing Description context with a new set of vocabularies.
Trait Implementations
sourceimpl Thing for BaseThing
impl Thing for BaseThing
sourcefn as_thing_description(&self) -> Map<String, Value>
fn as_thing_description(&self) -> Map<String, Value>
Return the thing state as a Thing Description.
sourcefn as_mut_any(&mut self) -> &mut dyn Any
fn as_mut_any(&mut self) -> &mut dyn Any
Return this thing as a mutable Any.
sourcefn get_href_prefix(&self) -> String
fn get_href_prefix(&self) -> String
Get this thing’s href prefix, i.e. /0.
sourcefn get_ui_href(&self) -> Option<String>
fn get_ui_href(&self) -> Option<String>
Get the UI href.
sourcefn set_href_prefix(&mut self, prefix: String)
fn set_href_prefix(&mut self, prefix: String)
Set the prefix of any hrefs associated with this thing.
sourcefn set_ui_href(&mut self, href: String)
fn set_ui_href(&mut self, href: String)
Set the href of this thing’s custom UI.
sourcefn get_context(&self) -> Value
fn get_context(&self) -> Value
Get the type context of the thing.
sourcefn get_type(&self) -> Vec<String>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
fn get_type(&self) -> Vec<String>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
A: Allocator,
Get the type(s) of the thing.
sourcefn get_description(&self) -> String
fn get_description(&self) -> String
Get the description of the thing.
sourcefn get_property_descriptions(&self) -> Map<String, Value>
fn get_property_descriptions(&self) -> Map<String, Value>
Get the thing’s properties as a JSON map.
Returns the properties as a JSON map, i.e. name -> description.
sourcefn get_action_descriptions(&self, action_name: Option<String>) -> Value
fn get_action_descriptions(&self, action_name: Option<String>) -> Value
Get the thing’s actions as an array.
sourcefn get_event_descriptions(&self, event_name: Option<String>) -> Value
fn get_event_descriptions(&self, event_name: Option<String>) -> Value
Get the thing’s events as an array.
sourcefn add_property(&mut self, property: Box<dyn Property>)
fn add_property(&mut self, property: Box<dyn Property>)
Add a property to this thing.
sourcefn remove_property(&mut self, property_name: &str)
fn remove_property(&mut self, property_name: &str)
Remove a property from this thing.
sourcefn find_property(
&mut self,
property_name: &str
) -> Option<&mut Box<dyn Property>>
fn find_property(
&mut self,
property_name: &str
) -> Option<&mut Box<dyn Property>>
Find a property by name.
sourcefn get_property(&self, property_name: &str) -> Option<Value>
fn get_property(&self, property_name: &str) -> Option<Value>
Get a property’s value.
sourcefn get_properties(&self) -> Map<String, Value>
fn get_properties(&self) -> Map<String, Value>
Get a mapping of all properties and their values.
Returns an object of propertyName -> value.
sourcefn has_property(&self, property_name: &str) -> bool
fn has_property(&self, property_name: &str) -> bool
Determine whether or not this thing has a given property.
sourcefn get_action(
&self,
action_name: String,
action_id: String
) -> Option<Arc<RwLock<Box<dyn Action>>>>
fn get_action(
&self,
action_name: String,
action_id: String
) -> Option<Arc<RwLock<Box<dyn Action>>>>
Get an action.
sourcefn add_available_event(&mut self, name: String, metadata: Map<String, Value>)
fn add_available_event(&mut self, name: String, metadata: Map<String, Value>)
Add an available event.
Arguments
name
- name of the eventmetadata
- event metadata, i.e. type, description, etc., as a JSON map
sourcefn add_action(
&mut self,
action: Arc<RwLock<Box<dyn Action>>>,
input: Option<&Value>
) -> Result<(), &str>
fn add_action(
&mut self,
action: Arc<RwLock<Box<dyn Action>>>,
input: Option<&Value>
) -> Result<(), &str>
Perform an action on the thing.
Returns the action that was created.
sourcefn remove_action(&mut self, action_name: String, action_id: String) -> bool
fn remove_action(&mut self, action_name: String, action_id: String) -> bool
Remove an existing action.
Returns a boolean indicating the presence of the action.
sourcefn add_available_action(&mut self, name: String, metadata: Map<String, Value>)
fn add_available_action(&mut self, name: String, metadata: Map<String, Value>)
Add an available action.
Arguments
name
- name of the actionmetadata
- action metadata, i.e. type, description, etc., as a JSON map
sourcefn add_subscriber(&mut self, ws_id: String)
fn add_subscriber(&mut self, ws_id: String)
sourcefn remove_subscriber(&mut self, ws_id: String)
fn remove_subscriber(&mut self, ws_id: String)
sourcefn add_event_subscriber(&mut self, name: String, ws_id: String)
fn add_event_subscriber(&mut self, name: String, ws_id: String)
Add a new websocket subscriber to an event.
Arguments
name
- name of the eventws_id
- ID of the websocket
sourcefn remove_event_subscriber(&mut self, name: String, ws_id: String)
fn remove_event_subscriber(&mut self, name: String, ws_id: String)
Remove a websocket subscriber from an event.
Arguments
name
- name of the eventws_id
- ID of the websocket
sourcefn property_notify(&mut self, name: String, value: Value)
fn property_notify(&mut self, name: String, value: Value)
Notify all subscribers of a property change.
sourcefn action_notify(&mut self, action: Map<String, Value>)
fn action_notify(&mut self, action: Map<String, Value>)
Notify all subscribers of an action status change.
sourcefn event_notify(&mut self, name: String, event: Map<String, Value>)
fn event_notify(&mut self, name: String, event: Map<String, Value>)
Notify all subscribers of an event.
sourcefn start_action(&mut self, name: String, id: String)
fn start_action(&mut self, name: String, id: String)
Start the specified action.
sourcefn cancel_action(&mut self, name: String, id: String)
fn cancel_action(&mut self, name: String, id: String)
Cancel the specified action.
sourcefn finish_action(&mut self, name: String, id: String)
fn finish_action(&mut self, name: String, id: String)
Finish the specified action.