#[repr(transparent)]pub struct Path(_);
Expand description
A Path
is a vector of Component
s.
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
impl Path
sourcepub fn into_typed(self, link_type: impl Into<ScopedLinkType>) -> TypedPath
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
.
sourcepub fn typed<TY, E>(self, link_type: TY) -> Result<TypedPath, WasmError>where
ScopedLinkType: TryFrom<TY, Error = E>,
WasmError: From<E>,
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
.
sourcepub fn path_entry_hash(&self) -> ExternResult<EntryHash>
pub fn path_entry_hash(&self) -> ExternResult<EntryHash>
What is the hash for the current Path
?
sourcepub fn append_component(&mut self, component: Component)
pub fn append_component(&mut self, component: Component)
Mutate this Path
into a child of itself by appending a Component
.
Trait Implementations§
source§impl<'de> Deserialize<'de> for Path
impl<'de> Deserialize<'de> for Path
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl From<&Anchor> for Path
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§impl From<&str> for Path
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§impl From<(&ShardStrategy, &[u8])> for Path
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§impl From<(&ShardStrategy, &Vec<u8, Global>)> for Path
impl From<(&ShardStrategy, &Vec<u8, Global>)> for Path
Wrapper around &Vec<u8>
to work the same as &u8.
source§impl From<(&ShardStrategy, &str)> for Path
impl From<(&ShardStrategy, &str)> for Path
source§impl From<(&ShardStrategy, Vec<u8, Global>)> for Path
impl From<(&ShardStrategy, Vec<u8, Global>)> for Path
Wrapper around Vec<u8>
to work the same as &u8.
source§impl PartialEq<Path> for Path
impl PartialEq<Path> for Path
source§impl TryFrom<&Path> for Anchor
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.