pub struct LayerStackBuilder<R> { /* private fields */ }Expand description
Builds a LayerStack from a main layer through a LayerResolver.
Implementations§
Source§impl<R: LayerResolver> LayerStackBuilder<R>
impl<R: LayerResolver> LayerStackBuilder<R>
pub fn new(resolver: R) -> Self
Sourcepub fn allow_cycles(self, allow: bool) -> Self
pub fn allow_cycles(self, allow: bool) -> Self
Accept import cycles and skip the import that closes one, as upstream
does. Off by default, so cycles are a LayerError::Cycle.
The skipped import names a layer that is still being loaded, so that
layer is already placed: it comes after the importer that closes the
cycle and overrides it, and the main layer stays last. For
main → a → main the stack is a, main.
pub fn resolver(&self) -> &R
pub fn resolver_mut(&mut self) -> &mut R
pub fn into_resolver(self) -> R
Sourcepub fn build(&mut self, main: &str) -> Result<LayerStack, LayerError<R::Error>>
pub fn build(&mut self, main: &str) -> Result<LayerStack, LayerError<R::Error>>
Loads the layer main names and, recursively, its imports, in the
order described in the module docs: the main layer last.
Sourcepub fn build_all<I>(
&mut self,
uris: I,
) -> Result<LayerStack, LayerError<R::Error>>
pub fn build_all<I>( &mut self, uris: I, ) -> Result<LayerStack, LayerError<R::Error>>
Loads several layers given weakest first, and recursively their
imports, as if they were the imports of a main layer without data.
This is how upstream’s ifcx compose and viewer stack the files a
user names, so the last one wins.
The stack holds only the named layers and their imports, in the order
build would give them below that main layer: each
named layer after its own imports, which it overrides, and the named
layers in the order given, so a later one overrides an earlier one and
everything that one imports. A layer named twice, or also imported,
loads once, where it is first reached. The last layer of the stack is
its main layer and gives the federated header.
uris resolve with no importer, as build’s main does. At least
one is needed; with none, the result is LayerError::Missing for an
empty URI.
use openbim_ifcx::layers::{LayerStackBuilder, MemoryResolver};
let layer = |id: &str| format!(r#"{{
"header": {{"id": "{id}", "ifcxVersion": "ifcx_alpha", "dataVersion": "1.0.0",
"author": "someone", "timestamp": "2026-10-03"}},
"imports": [], "schemas": {{}},
"data": [{{"path": "p1", "attributes": {{"demo::value": "{id}"}}}}]
}}"#);
let mut resolver = MemoryResolver::new();
resolver.insert("base", layer("base"));
resolver.insert("overlay", layer("overlay"));
let stack = LayerStackBuilder::new(resolver).build_all(["base", "overlay"])?;
assert_eq!(stack.keys().collect::<Vec<_>>(), ["base", "overlay"]);
assert_eq!(stack.main().key(), "overlay");
assert_eq!(stack.federate().header.id, "overlay");