pub struct MetaLink {
pub path: Vec<Seg>,
pub relation: RelationFacet,
pub link: Link,
pub kind: TargetKind,
}Expand description
One link declared by a document’s metadata.
Fields§
§path: Vec<Seg>Where the link sits in the metadata: [Key("part_of")] for a scalar
relation, [Key("contents"), Index(2)] for the third item of a list.
The path a frontend compares against its cursor.
relation: RelationFacetThe relation that declared it, and everything the vocabulary says about that relation — including whether it is the spanning backbone and whether it is a one-way pointer at machinery.
link: LinkThe parsed link: its label, its target, and which wrapper it was written
in. Link::render puts it back the way it came.
kind: TargetKindWhat shape of thing the target names, by syntax.
Implementations§
Source§impl MetaLink
impl MetaLink
Sourcepub fn locator(&self) -> Option<&str>
pub fn locator(&self) -> Option<&str>
The #locator suffix, when the target has one — a place inside the
document the rest of the target names. Carried by prov, never resolved.
Sourcepub fn display(&self) -> &str
pub fn display(&self) -> &str
What to put on a row: the link’s label when it was written with one, and the target otherwise. A labeled link is labeled because the target is not what a reader wants to read.
Examples found in repository?
7fn main() {
8 let path = std::path::PathBuf::from(std::env::args().nth(1).expect("a document"));
9 let view = WorkspaceView::discover(&path).expect("discovery");
10 match &view {
11 Some(v) => println!("workspace: {}", v.root_dir().display()),
12 None => println!("workspace: none"),
13 }
14 let facets = view
15 .as_ref()
16 .map(|v| v.facets().clone())
17 .unwrap_or_default();
18 let schema = view.as_ref().map(|v| v.schema_for(&path));
19 let session =
20 DocumentSession::open_managed(&path, schema, facets.managed_key_names()).expect("open");
21
22 println!("\nkeys:");
23 for (key, facet) in facets.classify(session.meta()) {
24 let flags = [
25 facet.structural().then_some("structural"),
26 facet.managed().then_some("managed"),
27 ]
28 .into_iter()
29 .flatten()
30 .collect::<Vec<_>>()
31 .join(",");
32 println!(" {key:<14} {:<9} {flags}", facet.kind());
33 }
34
35 println!("\nlinks:");
36 for link in links_in(session.meta(), &facets) {
37 let landing = match &view {
38 Some(v) => v.resolve(&path, &link),
39 None => resolve_without_workspace(&path, &link),
40 };
41 let mark = if matches!(landing, Destination::Document { exists: true, .. }) {
42 "→"
43 } else {
44 "·"
45 };
46 println!(
47 " {mark} {:<10} {:<22} {}",
48 link.relation.name,
49 link.display(),
50 landing.describe()
51 );
52 }
53}Sourcepub fn leaves_the_workspace(&self) -> bool
pub fn leaves_the_workspace(&self) -> bool
Whether following this link would leave the workspace — a URL, or a reference into a workspace prov cannot locate from here.