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() -> Config
pub fn empty() -> Config
Returns an empty config.
Note that this may differ from the Default implementation, which
includes hard-coded global defaults.
Sourcepub async fn global_defaults() -> Result<Config, Error>
pub async fn global_defaults() -> Result<Config, 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 async fn read_global_config() -> Result<Option<Config>, Error>
pub async fn read_global_config() -> Result<Option<Config>, Error>
Reads config from the default global config file location
Sourcepub fn global_config_path() -> Option<PathBuf>
pub fn global_config_path() -> Option<PathBuf>
Returns the default global config file location
Sourcepub async fn from_file(path: impl AsRef<Path>) -> Result<Config, Error>
pub async fn from_file(path: impl AsRef<Path>) -> Result<Config, Error>
Reads config from a TOML file at the given path.
Sourcepub fn from_toml(contents: &str) -> Result<Config, Error>
pub fn from_toml(contents: &str) -> Result<Config, Error>
Parses config from the given TOML contents.
Sourcepub async fn to_file(&self, path: impl AsRef<Path>) -> Result<(), Error>
pub async fn to_file(&self, path: impl AsRef<Path>) -> Result<(), Error>
Writes the config to a TOML file at the given path.
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<&RegistryMapping>
pub fn namespace_registry(&self, namespace: &Label) -> Option<&RegistryMapping>
Returns a registry for the given namespace.
Does not fall back to the default registry; see
Self::resolve_registry.
Sourcepub fn set_namespace_registry(
&mut self,
namespace: Label,
registry: RegistryMapping,
)
pub fn set_namespace_registry( &mut self, namespace: Label, registry: RegistryMapping, )
Sets a registry for the given namespace.
Sourcepub fn package_registry_override(
&self,
package: &PackageRef,
) -> Option<&RegistryMapping>
pub fn package_registry_override( &self, package: &PackageRef, ) -> Option<&RegistryMapping>
Returns a registry override configured for the given package.
Does not fall back to namespace or default registries; see
Self::resolve_registry.
Sourcepub fn set_package_registry_override(
&mut self,
package: PackageRef,
registry: RegistryMapping,
)
pub fn set_package_registry_override( &mut self, package: PackageRef, registry: RegistryMapping, )
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.
Trait Implementations§
Source§impl Serialize for Config
impl Serialize for Config
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl !Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnwindSafe for Config
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more