wasm_pkg_common::config

Struct 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

Source

pub fn empty() -> Self

Returns an empty config.

Note that this may differ from the Default implementation, which includes hard-coded global defaults.

Source

pub async 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.

Source

pub fn global_config_path() -> Option<PathBuf>

Returns the default global config file location

Source

pub async fn read_global_config() -> Result<Option<Self>, Error>

Reads config from the default global config file location

Source

pub async fn from_file(path: impl AsRef<Path>) -> Result<Self, Error>

Reads config from a TOML file at the given path.

Source

pub fn from_toml(contents: &str) -> Result<Self, Error>

Parses config from the given TOML contents.

Source

pub async fn to_file(&self, path: impl AsRef<Path>) -> Result<(), Error>

Writes the config to a TOML file at the given path.

Source

pub fn merge(&mut self, other: Self)

Merges the given other config into this one.

Source

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
Source

pub fn default_registry(&self) -> Option<&Registry>

Returns the default registry.

Source

pub fn set_default_registry(&mut self, registry: Option<Registry>)

Sets the default registry.

To unset the default registry, pass None.

Source

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.

Source

pub fn set_namespace_registry( &mut self, namespace: Label, registry: RegistryMapping, )

Sets a registry for the given namespace.

Source

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.

Source

pub fn set_package_registry_override( &mut self, package: PackageRef, registry: RegistryMapping, )

Sets a registry override for the given package.

Source

pub fn registry_config(&self, registry: &Registry) -> Option<&RegistryConfig>

Returns RegistryConfig for the given registry.

Source

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 Clone for Config

Source§

fn clone(&self) -> Config

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Config

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Serialize for Config

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.