Struct hdk::hash_path::path::Path

source ·
pub struct Path(/* private fields */);
Expand description

A Path is a vector of Components.

It represents a single traversal of a tree structure down to some arbitrary point. The main intent is that we can recursively walk back up the tree, hashing, committing and linking each sub-path along the way until we reach the root.

At this point it is possible to follow DHT links from the root back up the path, i.e. the ahead-of-time predictability of the hashes of a given path allows us to travel “up” the tree and the linking functionality of the Holochain DHT allows us to travel “down” the tree after at least one DHT participant has followed the path “up”.

Implementations§

source§

impl Path

source

pub fn into_typed(self, link_type: impl Into<ScopedLinkType>) -> TypedPath

Attach a LinkType to this path so its type is known for create_link and get_links.

source

pub fn typed<TY, E>(self, link_type: TY) -> Result<TypedPath, WasmError>
where ScopedLinkType: TryFrom<TY, Error = E>, WasmError: From<E>,

Try attaching a LinkType to this path so its type is known for create_link and get_links.

source

pub fn path_entry_hash(&self) -> ExternResult<EntryHash>

What is the hash for the current Path ?

source

pub fn append_component(&mut self, component: Component)

Mutate this Path into a child of itself by appending a Component.

source

pub fn leaf(&self) -> Option<&Component>

Accessor for the last Component of this Path. This can be thought of as the leaf of the implied tree structure of which this Path is one branch of.

source

pub fn make_tag(&self) -> ExternResult<LinkTag>

Make the LinkTag for this Path.

source

pub fn is_root(&self) -> bool

Check if this Path is the root.

Trait Implementations§

source§

impl AsRef<Vec<Component>> for Path

Access components vector.

source§

fn as_ref(&self) -> &Vec<Component>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Clone for Path

source§

fn clone(&self) -> Path

Returns a copy 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 Path

source§

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

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

impl Default for Path

source§

fn default() -> Path

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for Path

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<&Anchor> for Path

Anchors are just a special case of path, so we can move from anchor to path losslessly. We simply format the anchor structure into a string that works with the path string handling.

source§

fn from(anchor: &Anchor) -> Self

Converts to this type from the input type.
source§

impl From<&String> for Path

Alias From<&str>

source§

fn from(s: &String) -> Self

Converts to this type from the input type.
source§

impl From<&str> for Path

Split a string path out into a vector of components. This allows us to construct pseudo-URI-path-things as strings. It is a simpler scheme than URLs and file paths. Leading and trailing slashes are ignored as are duplicate dots and the empty string leads to a path with zero length (no components).

e.g. all the following result in the same components as vec!["foo", "bar"] (as bytes)

  • foo.bar
  • foo.bar.
  • .foo.bar
  • .foo.bar.
  • foo..bar

There is no normalisation of paths, e.g. to guarantee a specific root component exists, at this layer so there is a risk that there are hash collisions with other data on the DHT network if some disambiguation logic is not included in higher level abstractions.

This supports sharding strategies from a small inline DSL. Start each component with <width>:<depth># to get shards out of the string.

e.g.

  • foo.barbaz => normal path as above [“foo”, “barbaz”]
  • foo.1:3#barbazii => width 1, depth 3, [“foo”, “b”, “a”, “r”, “barbazii”]
  • foo.2:3#barbazii => width 2, depth 3, [“foo”, “ba”, “rb”, “az”, “barbazii”]

Note that this all works because the components and sharding for strings maps to fixed-width utf32 bytes under the hood rather than variable width bytes.

source§

fn from(s: &str) -> Self

Converts to this type from the input type.
source§

impl From<(&ShardStrategy, &[u8])> for Path

Builds a path for a shard strategy and some binary bytes. This is the trivial case, we just split the bytes out one by one and make a path from it.

source§

fn from((strategy, bytes): (&ShardStrategy, &[u8])) -> Path

Converts to this type from the input type.
source§

impl From<(&ShardStrategy, &String)> for Path

&String wrapper mimicking &str for Path building.

source§

fn from((strategy, s): (&ShardStrategy, &String)) -> Path

Converts to this type from the input type.
source§

impl From<(&ShardStrategy, &Vec<u8>)> for Path

Wrapper around &Vec<u8> to work the same as &u8.

source§

fn from((strategy, bytes): (&ShardStrategy, &Vec<u8>)) -> Path

Converts to this type from the input type.
source§

impl From<(&ShardStrategy, &str)> for Path

Create Path from String . To ensure that this works for all utf8, which can have anywhere from 1-4 bytes for a single character, we first represent each character as a utf32 so it gets padded out with 0 bytes. This means the width is 4x what it would be for raw bytes with the same strategy.

source§

fn from((strategy, s): (&ShardStrategy, &str)) -> Path

Converts to this type from the input type.
source§

impl From<(&ShardStrategy, String)> for Path

source§

fn from((strategy, s): (&ShardStrategy, String)) -> Path

Converts to this type from the input type.
source§

impl From<(&ShardStrategy, Vec<u8>)> for Path

Wrapper around Vec<u8> to work the same as &u8.

source§

fn from((strategy, bytes): (&ShardStrategy, Vec<u8>)) -> Path

Converts to this type from the input type.
source§

impl From<Path> for Vec<Component>

Unwrap components vector.

source§

fn from(path: Path) -> Self

Converts to this type from the input type.
source§

impl From<String> for Path

Alias From<&str>

source§

fn from(s: String) -> Self

Converts to this type from the input type.
source§

impl From<TypedPath> for Path

source§

fn from(p: TypedPath) -> Self

Converts to this type from the input type.
source§

impl From<Vec<Component>> for Path

Wrap components vector.

source§

fn from(components: Vec<Component>) -> Self

Converts to this type from the input type.
source§

impl PartialEq for Path

source§

fn eq(&self, other: &Path) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Path

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
source§

impl TryFrom<&Path> for Anchor

Paths are more general than anchors so a path could be represented that is not a valid anchor. The obvious example would be a path of binary data that is not valid utf-8 strings or a path that is more than 2 levels deep.

§

type Error = WasmError

The type returned in the event of a conversion error.
source§

fn try_from(path: &Path) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Path> for SerializedBytes

§

type Error = SerializedBytesError

The type returned in the event of a conversion error.
source§

fn try_from(t: &Path) -> Result<SerializedBytes, SerializedBytesError>

Performs the conversion.
source§

impl TryFrom<Path> for SerializedBytes

§

type Error = SerializedBytesError

The type returned in the event of a conversion error.
source§

fn try_from(t: Path) -> Result<SerializedBytes, SerializedBytesError>

Performs the conversion.
source§

impl TryFrom<SerializedBytes> for Path

§

type Error = SerializedBytesError

The type returned in the event of a conversion error.
source§

fn try_from(sb: SerializedBytes) -> Result<Path, SerializedBytesError>

Performs the conversion.
source§

impl TryInto<String> for Path

§

type Error = SerializedBytesError

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<String, Self::Error>

Performs the conversion.
source§

impl StructuralPartialEq for Path

Auto Trait Implementations§

§

impl Freeze for Path

§

impl RefUnwindSafe for Path

§

impl Send for Path

§

impl Sync for Path

§

impl Unpin for Path

§

impl UnwindSafe for Path

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

§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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<F, W, T, D> Deserialize<With<T, W>, D> for F
where W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

source§

fn deserialize( &self, deserializer: &mut D ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
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> LayoutRaw for T

source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Gets the layout of the type.
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Pointee for T

§

type Metadata = ()

The type for metadata in pointers and references to Self.
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for T
where T: Clone,

§

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>,

§

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>,

§

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<T> Upcastable for T
where T: Any + Send + Sync + 'static,

source§

fn upcast_any_ref(&self) -> &(dyn Any + 'static)

upcast ref
source§

fn upcast_any_mut(&mut self) -> &mut (dyn Any + 'static)

upcast mut ref
source§

fn upcast_any_box(self: Box<T>) -> Box<dyn Any>

upcast boxed dyn
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>,