Expand description
§Dynamically-typed XSOs
This module provides the utilities to make dynamically-typed XSOs work.
Dynamically typed XSOs are for example contained in
Xso<dyn Trait> or XsoVec<dyn Trait>, where
Trait is a trait provided and defined by the user.
The given Trait constrains the specific types which can be used in the
Xso<dyn Trait> box. This allows users to provide additional methods on
the trait which are available on all Xso<dyn Trait> objects via the
Deref and DerefMut
implementations.
Xso<dyn Trait> (and also XsoVec<dyn Trait>) can be parsed
from XML and serialised to XML, provided some constraints are fulfilled.
For serialisation, the Trait must have a bound on AsXmlDyn, requiring
all implementors of the trait to implement AsXml.
For parsing, all implementations of the trait must register themselves
with the trait so that the FromXml implementation knows about them and
can use them to parse the XML data. How this is done is depends on the way
the trait is declared.
XSO supports three ways of doing so:
-
Using the
linktimemacro (requiring thelinktimecrate feature) strictly at compile-time / linking-time of the final application binary.This is the recommended way as it incurs a very low runtime overhead and does not depend on
stdeither. -
Using the
std-basedBuilderRegistrythrough thexso_traitmacro. -
Using a custom registry through the
xso_traitmacro.
Please refer to the linked macros for usage details and examples.
§Dynamically-typed XSOs vs. enums
One key question you should ask yourself when looking at this module and before going down the route of dynamically-typed XSOs is: “Is an enum enough for my use-case?”
The key difference between dynamically-typed XSOs and enums is that enums cannot be extended by other crates, or even outside the source file they are declared in. Dynamically-typed XSOs can be extended by any code place where a trait implementation of that dynamic XSO trait is possible, which is virtually anywhere.
Dynamically-typed XSOs are thus more useful in plugin-like situations or when providing an extension point for other crates. Enums are more useful when you know the exact variants of acceptable XML data. Enums are generally likely to be more performant, as the lookups needed can be hardcoded and arbitrarily optimized by the compiler.
Modules§
Macros§
- linktime
linktime - Dynamic XSO traits using a link-time registry
- xso_
trait - Make a trait usable as dynamic XSO trait.
Structs§
- Builder
Registry std - Registry for type-erased
FromXmlbuilders which constructT - DynBuilder
- Wrapper around a
FromEventsBuilderto convert aBox<T>output to aXso<T>output. - Unbox
Builder - Wrapper around a
FromEventsBuilderto convert aBox<T>output to aToutput. - Xso
- Dynamic XSO container
- XsoVec
- Container for dynamically-typed XSOs optimized for type-keyed access
Enums§
- Take
OneError - Error type for retrieving a single item from
XsoVec.
Traits§
- DynXso
- Dynamic XSO type
- MayContain
- Declare that
Tmay be held byBox<Self>