Struct Resource

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

A Resource is a set of Atoms that shares a single Subject. A Resource only contains valid Values, but it might lack required properties. All changes to the Resource are applied after committing them (e.g. by using).

Implementations§

Source§

impl Resource

Source

pub fn check_required_props(&self, store: &impl Storelike) -> AtomicResult<()>

Fetches all ‘required’ properties. Returns an error if any are missing in this Resource.

Source

pub fn destroy( &mut self, store: &impl Storelike, ) -> AtomicResult<CommitResponse>

Removes / deletes the resource from the store by performing a Commit. Recursively deletes the resource’s children.

Source

pub fn get_children( &self, store: &impl Storelike, ) -> AtomicResult<Vec<Resource>>

Gets the children of this resource.

Source

pub fn from_propvals(propvals: PropVals, subject: String) -> Resource

Source

pub fn get(&self, property_url: &str) -> AtomicResult<&Value>

Get a value by property URL

Source

pub fn get_commit_builder(&self) -> &CommitBuilder

Source

pub fn get_classes(&self, store: &impl Storelike) -> AtomicResult<Vec<Class>>

Checks if the classes are there, if not, fetches them. Returns an empty vector if there are no classes found.

Source

pub fn get_main_class(&self) -> AtomicResult<String>

Returns the first item of the is_ array

Source

pub fn get_parent(&self, store: &impl Storelike) -> AtomicResult<Resource>

Returns the Parent of this Resource. Throws in case of recursion

Source

pub fn get_parent_tree( &self, store: &impl Storelike, ) -> AtomicResult<Vec<Resource>>

Walks the parent tree upwards until there is no parent, then returns them as a vector.

Source

pub fn get_propvals(&self) -> &PropVals

Returns all PropVals. Useful if you want to iterate over all Atoms / Properties.

Source

pub fn get_shortname( &self, shortname: &str, store: &impl Storelike, ) -> AtomicResult<&Value>

Gets a value by its property shortname or property URL.

Source

pub fn get_subject(&self) -> &String

Source

pub fn has_parent(&self, store: &impl Storelike, parent: &str) -> bool

checks if a resouce has a specific parent. iterates over all parents.

Source

pub fn into_propvals(self) -> PropVals

Returns all PropVals.

Source

pub fn new(subject: String) -> Resource

Create a new, empty Resource.

Source

pub fn random_subject(store: &impl Storelike) -> String

Source

pub fn new_generate_subject(store: &impl Storelike) -> Resource

Create a new resource with a generated Subject

Source

pub fn new_instance( class_url: &str, store: &impl Storelike, ) -> AtomicResult<Resource>

Create a new instance of some Class. The subject is generated, but can be changed. Does not save the resource to the store.

Source

pub fn push( &mut self, property: &str, value: SubResource, skip_existing: bool, ) -> AtomicResult<&mut Self>

Appends a Resource to a specific property through the commitbuilder. Useful if you want to have compact Commits that add things to existing ResourceArrays.

Source

pub fn remove_propval(&mut self, property_url: &str)

Remove a propval from a resource by property URL.

Source

pub fn remove_propval_shortname( &mut self, property_shortname: &str, store: &impl Storelike, ) -> AtomicResult<()>

Remove a propval from a resource by property URL or shortname. Returns error if propval does not exist in this resource or its class.

Source

pub fn resolve_shortname_to_property( &self, shortname: &str, store: &impl Storelike, ) -> AtomicResult<Property>

Tries to resolve the shortname of a Property to a Property. Currently only tries the shortnames for linked classes - not for other properties.

Source

pub fn reset_commit_builder(&mut self)

Source

pub fn save(&mut self, store: &impl Storelike) -> AtomicResult<CommitResponse>

Saves the resource (with all the changes) to the store by creating a Commit. Uses default Agent to sign the Commit. Stores changes on the Subject’s Server by sending a Commit. Returns the generated Commit, the new Resource and the old Resource.

Source

pub fn save_locally( &mut self, store: &impl Storelike, ) -> AtomicResult<CommitResponse>

Saves the resource (with all the changes) to the store by creating a Commit. Uses default Agent to sign the Commit. Returns the generated Commit and the new Resource. Does not validate rights / hierarchy. Does not store these changes on the server of the Subject - the Commit will be lost, unless you handle it manually.

Source

pub fn set_class(&mut self, is_a: &str)

Overwrites the is_a (Class) of the Resource.

Source

pub fn set_string( &mut self, property_url: String, value: &str, store: &impl Storelike, ) -> AtomicResult<&mut Self>

Insert a Property/Value combination. Overwrites existing Property/Value. Validates the datatype.

Source

pub fn set( &mut self, property: String, value: Value, store: &impl Storelike, ) -> AtomicResult<&mut Self>

Inserts a Property/Value combination. Checks datatype. Overwrites existing. Adds the change to the commit builder’s set map.

Source

pub fn set_unsafe(&mut self, property: String, value: Value) -> &mut Self

Does not validate property / datatype combination. Inserts a Property/Value combination. Overwrites existing. Adds it to the CommitBuilder.

Source

pub fn set_shortname( &mut self, property: &str, value: &str, store: &impl Storelike, ) -> AtomicResult<&mut Self>

Sets a property / value combination. Property can be a shortname (e.g. ‘description’ instead of the full URL). Returns error if propval does not exist in this resource or its class.

Source

pub fn set_propvals_unsafe(&mut self, propvals: PropVals)

Overwrites all current PropVals. Does not perform validation.

Source

pub fn set_subject(&mut self, url: String) -> &mut Self

Changes the subject of the Resource. Does not ‘move’ the Resource See https://github.com/atomicdata-dev/atomic-server/issues/44

Source

pub fn to_json_ad(&self) -> AtomicResult<String>

Converts Resource to JSON-AD string.

Source

pub fn to_json(&self, store: &impl Storelike) -> AtomicResult<String>

Converts Resource to plain JSON string.

Source

pub fn to_json_ld(&self, store: &impl Storelike) -> AtomicResult<String>

Converts Resource to JSON-LD string, with @context object and RDF compatibility.

Source

pub fn to_atoms(&self) -> Vec<Atom>

Trait Implementations§

Source§

impl Clone for Resource

Source§

fn clone(&self) -> Resource

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Resource

Source§

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

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

impl<'de> Deserialize<'de> for Resource

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 From<Resource> for SubResource

Source§

fn from(val: Resource) -> Self

Converts to this type from the input type.
Source§

impl From<Resource> for Value

Source§

fn from(val: Resource) -> Self

Converts to this type from the input type.
Source§

impl Serialize for Resource

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

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

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

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

Source§

impl<T> ErasedDestructor for T
where T: 'static,