Struct wasm_pkg_common::config::Config
source · pub struct Config { /* private fields */ }Expand description
Wasm Package registry configuration.
Most consumers are expected to start with Config::global_defaults to
provide a consistent baseline user experience. Where needed, these defaults
can be overridden with application-specific config via Config::merge or
other mutation methods.
Implementations§
source§impl Config
impl Config
sourcepub fn empty() -> Self
pub fn empty() -> Self
Returns an empty config.
Note that this may differ from the Default implementation, which
includes hard-coded global defaults.
sourcepub fn global_defaults() -> Result<Self, Error>
pub fn global_defaults() -> Result<Self, Error>
Loads config from several default sources.
The following sources are loaded in this order, with later sources merged into (overriding) earlier sources.
- Hard-coded defaults
- User-global config file (e.g.
~/.config/wasm-pkg/config.toml)
Note: This list is expected to expand in the future to include
“workspace” config files like ./.wasm-pkg/config.toml.
sourcepub fn read_global_config() -> Result<Option<Self>, Error>
pub fn read_global_config() -> Result<Option<Self>, Error>
Reads config from the default global config file location
sourcepub fn from_file(path: impl AsRef<Path>) -> Result<Self, Error>
pub fn from_file(path: impl AsRef<Path>) -> Result<Self, Error>
Reads config from a TOML file at the given path.
sourcepub fn from_toml(contents: &str) -> Result<Self, Error>
pub fn from_toml(contents: &str) -> Result<Self, Error>
Parses config from the given TOML contents.
sourcepub fn resolve_registry(&self, package: &PackageRef) -> Option<&Registry>
pub fn resolve_registry(&self, package: &PackageRef) -> Option<&Registry>
Resolves a Registry for the given PackageRef.
Resolution returns the first of these that matches:
- A package registry exactly matching the package
- A namespace registry matching the package’s namespace
- The default registry
- Hard-coded fallbacks for certain well-known namespaces
sourcepub fn default_registry(&self) -> Option<&Registry>
pub fn default_registry(&self) -> Option<&Registry>
Returns the default registry.
sourcepub fn set_default_registry(&mut self, registry: Option<Registry>)
pub fn set_default_registry(&mut self, registry: Option<Registry>)
Sets the default registry.
To unset the default registry, pass None.
sourcepub fn namespace_registry(&self, namespace: &Label) -> Option<&Registry>
pub fn namespace_registry(&self, namespace: &Label) -> Option<&Registry>
Returns a registry for the given namespace.
Does not fall back to the default registry; see [Self::resolve].
sourcepub fn set_namespace_registry(&mut self, namespace: Label, registry: Registry)
pub fn set_namespace_registry(&mut self, namespace: Label, registry: Registry)
Sets a registry for the given namespace.
sourcepub fn package_registry_override(
&self,
package: &PackageRef,
) -> Option<&Registry>
pub fn package_registry_override( &self, package: &PackageRef, ) -> Option<&Registry>
Returns a registry override configured for the given package.
Does not fall back to namespace or default registries; see [Self::resolve].
sourcepub fn set_package_registry_override(
&mut self,
package: PackageRef,
registry: Registry,
)
pub fn set_package_registry_override( &mut self, package: PackageRef, registry: Registry, )
Sets a registry override for the given package.
sourcepub fn registry_config(&self, registry: &Registry) -> Option<&RegistryConfig>
pub fn registry_config(&self, registry: &Registry) -> Option<&RegistryConfig>
Returns RegistryConfig for the given registry.
sourcepub fn get_or_insert_registry_config_mut(
&mut self,
registry: &Registry,
) -> &mut RegistryConfig
pub fn get_or_insert_registry_config_mut( &mut self, registry: &Registry, ) -> &mut RegistryConfig
Returns a mutable RegistryConfig for the given registry, inserting
an empty one if needed.