Skip to content

Conversation

@Adobels
Copy link
Contributor

@Adobels Adobels commented Dec 30, 2025

Motivation

Closes #96

Modifications

Add the ExpressibleByConfigInt protocol, mirroring ExpressibleByConfigString.
Add an ExpressibleByConfigInt extension for the Swift.Duration type.

Result

Convert configuration values of int and intArray to a type that conforms to ExpressibleByConfigInt, or to an enumeration with Int raw values.
Configuration values expressed in seconds can be converted directly to the Swift.Duration type.

Test Plan

Add tests based on the existing ExpressibleByConfigString tests.

extension Duration: ExpressibleByConfigInt {
// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
public init?(configInt: Int) {
self = .seconds(configInt)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll play devil's advocate here. I understand that the standard time unit is the second, but for example in STOMPNIO I get a Duration type from config, except that in the STOMP protocol the time unit used is milliseconds (this is accurately documented in DocC, of course).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code matches my understanding of the issue — specifically, that it allows directly initializing Duration using the default unit.
Do you see any issues with this approach, especially regarding unit assumptions, @czechboy0?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good question, basically: is there a single obvious conversion from Int -> Duration, or are there multiple equally expected ones?

I'd still argue that seconds, being an SI unit, is the most obvious projection from Int. And if you want Duration from milliseconds, you just need to wrap the call to int(forKey:) and construct it manually. This part could, in the future, be made easier with: #22.

@Adobels Adobels force-pushed the Add-expressibleByConfigInt branch from 3947083 to fe4e40c Compare January 8, 2026 14:38
@Adobels Adobels marked this pull request as ready for review January 8, 2026 21:24
@Adobels Adobels requested a review from czechboy0 January 10, 2026 15:07
@czechboy0
Copy link
Contributor

Thanks @Adobels - the PR looks basically ready, can you write up a short proposal for it as per https://swiftpackageindex.com/apple/swift-configuration/1.0.0/documentation/configuration/proposals - won't need to be long, we just want to give the community a chance to chime in. Thanks! 🙏

@Adobels Adobels marked this pull request as draft January 12, 2026 17:28
@Adobels Adobels marked this pull request as ready for review January 12, 2026 17:28
@Adobels
Copy link
Contributor Author

Adobels commented Jan 12, 2026

Thanks @Adobels - the PR looks basically ready, can you write up a short proposal for it as per https://swiftpackageindex.com/apple/swift-configuration/1.0.0/documentation/configuration/proposals - won't need to be long, we just want to give the community a chance to chime in. Thanks! 🙏

I'm ready for a review

@czechboy0 czechboy0 changed the title Add ExpressibleByConfigInt SCO-0004: Add ExpressibleByConfigInt Jan 13, 2026
@czechboy0
Copy link
Contributor

This proposal is now In Review until January 25th: https://forums.swift.org/t/proposal-sco-0004-add-expressiblebyconfigint/84109

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ExpressibleByConfigInt

3 participants