Skip to content

Commit

Permalink
Provide instance level access to descriptor information
Browse files Browse the repository at this point in the history
Motivation:

Sometimes developers are working in type-erased contexts where they can't directly refer to the name of the type of the `CurrencyValue` and need access to the descriptor.

In this cases, having an instance member property to provide the value is straight forward and convenient.

Modifications:

- Add: `descriptor` instance property to `CurrencyValue`
- Add: `@inlinable` annotations to both the static and instance member `descriptor` properties

Result:

Developers now have access to the `CurrencyValue` descriptor type either at the type or instance level.
  • Loading branch information
Mordil committed Jan 7, 2025
1 parent 530df0d commit 756af82
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Sources/Currency/CurrencyValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public protocol CurrencyValue:
AdditiveArithmetic
{
/// The information describing the currency.
static var descriptor: CurrencyDescriptor.Type { get }
@inlinable
static var descriptor: any CurrencyDescriptor.Type { get }

/// The exact amount of money being represented,
/// even if the value is fractional of what the currency uses for its minor units.
Expand All @@ -52,12 +53,20 @@ public protocol CurrencyValue:
// MARK: Defaults

extension CurrencyValue where Self: CurrencyDescriptor {
public static var descriptor: CurrencyDescriptor.Type { Self.self }
public static var descriptor: any CurrencyDescriptor.Type { Self.self }
}

// MARK: Extensions

extension CurrencyValue {
/// The information describing the currency.
///
/// This is primarily for use when working in type-erased contexts.
///
/// When possible, prefer the static property ``descriptor-40dnd`` instead.
@inlinable
public var descriptor: any CurrencyDescriptor.Type { Self.descriptor }

/// The amount represented as a whole number of the curreny's "minor units".
///
/// For example, as the USD uses 1/100 for its minor unit,
Expand Down

0 comments on commit 756af82

Please sign in to comment.