pub struct Reference {
pub path: String,
pub type_info: Option<TypeInfo>,
}Expand description
A reference to a value at another path.
References are the foundation of HATEOAS in StructFS. Instead of embedding full values or documenting path construction rules, stores return references that clients can follow.
§Examples
use structfs_core_store::Reference;
// Minimal reference
let r = Reference::new("handles/0");
// Reference with type hint
let r = Reference::with_type("handles/0", "handle");
// Reference to an action
let r = Reference::with_type("meta/open", "action");Fields§
§path: StringThe path to the referenced value.
type_info: Option<TypeInfo>Optional type information.
Implementations§
Source§impl Reference
impl Reference
Sourcepub fn with_type(path: impl Into<String>, type_name: impl Into<String>) -> Self
pub fn with_type(path: impl Into<String>, type_name: impl Into<String>) -> Self
Create a reference with a type name.
Sourcepub fn to_value(&self) -> Value
pub fn to_value(&self) -> Value
Convert to a Value::Map representation.
This produces the canonical reference format:
{"path": "handles/0", "type": {"name": "handle"}}Sourcepub fn from_value(value: &Value) -> Option<Self>
pub fn from_value(value: &Value) -> Option<Self>
Try to parse a Reference from a Value.
A value is a reference if it’s a map containing a path key whose
value is a string.
Sourcepub fn is_reference(value: &Value) -> bool
pub fn is_reference(value: &Value) -> bool
Check if a Value is a reference.
A value is a reference if it’s a map containing a path key whose
value is a string.
Trait Implementations§
impl Eq for Reference
impl StructuralPartialEq for Reference
Auto Trait Implementations§
impl Freeze for Reference
impl RefUnwindSafe for Reference
impl Send for Reference
impl Sync for Reference
impl Unpin for Reference
impl UnsafeUnpin for Reference
impl UnwindSafe for Reference
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