-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrap SOME of Radix Engine Toolkit types, first of MANY PRs. (#3)
- Loading branch information
1 parent
3e9d604
commit 73af6c9
Showing
83 changed files
with
5,908 additions
and
776 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,17 @@ | ||
[all] | ||
exclude-files = [ | ||
"tests/*", | ||
"src/wrapped_radix_engine_toolkit/*", | ||
"example/*", | ||
"target/*", | ||
"apple/*", | ||
".swiftpm/*", | ||
"scripts/*", | ||
".build/*", | ||
"Package.swift", | ||
] | ||
verbose = false | ||
all-features = true | ||
timeout = "1800s" | ||
timeout = "5m" | ||
skip-clean = true | ||
out = ["Xml"] | ||
force-clean = false |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
apple/Sources/Sargon/Extensions/Methods/AppearanceID+Wrap+Functions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
extension AppearanceID: CaseIterable { | ||
public static var allCases: [Self] { | ||
appearanceIdsAll() | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
apple/Sources/Sargon/Extensions/Methods/BagOfBytes+Wrap+Functions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
extension BagOfBytes { | ||
public init(data: Data) { | ||
self = newBagOfBytesFrom(bytes: data) | ||
} | ||
} |
1 change: 0 additions & 1 deletion
1
apple/Sources/Sargon/Extensions/Methods/Decimal192+Methods.swift
This file was deleted.
Oops, something went wrong.
113 changes: 113 additions & 0 deletions
113
apple/Sources/Sargon/Extensions/Methods/Decimal192+Wrap+Functions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
extension Decimal192 { | ||
public init(_ string: String) throws { | ||
self = try newDecimalFromString(string: string) | ||
} | ||
} | ||
|
||
extension Decimal192: CustomStringConvertible { | ||
public var description: String { | ||
decimalToString(decimal: self) | ||
} | ||
} | ||
|
||
extension Decimal192 { | ||
public static let maxDivisibility: UInt8 = 18 | ||
} | ||
|
||
extension Decimal192 { | ||
/// Parse a local respecting string | ||
public init( | ||
formattedString: String, | ||
locale: Locale = .autoupdatingCurrent | ||
) throws { | ||
let localConfig: LocaleConfig = LocaleConfig(locale: locale) | ||
self = try newDecimalFromFormattedString( | ||
formattedString: formattedString, | ||
locale: localConfig | ||
) | ||
} | ||
} | ||
|
||
// MARK: Truncation and rounding | ||
|
||
extension Decimal192 { | ||
|
||
private func rounded(decimalPlaces: UInt8, roundingMode: RoundingMode) -> Self { | ||
precondition( | ||
decimalPlaces <= Decimal192.maxDivisibility, | ||
"Decimal places MUST be 0...18, was: \(decimalPlaces)" | ||
) | ||
do { | ||
return try decimalRound( | ||
decimal: self, | ||
decimalPlaces: Int32(decimalPlaces), | ||
roundingMode: roundingMode | ||
) | ||
} catch { | ||
fatalError("Failed to round, error: \(error)") | ||
} | ||
} | ||
|
||
|
||
/// Rounds to `decimalPlaces` decimals | ||
public func rounded(decimalPlaces: UInt8 = 0) -> Self { | ||
rounded( | ||
decimalPlaces: decimalPlaces, | ||
roundingMode: .toNearestMidpointAwayFromZero | ||
) | ||
} | ||
|
||
/// Rounds to `decimalPlaces` decimals, in the direction of 0 | ||
public func floor(decimalPlaces: UInt8) -> Self { | ||
rounded(decimalPlaces: decimalPlaces, roundingMode: .toZero) | ||
} | ||
|
||
/// Rounds to `decimalPlaces` decimals, in the direction away from zero | ||
public func ceil(decimalPlaces: UInt8) -> Self { | ||
rounded(decimalPlaces: decimalPlaces, roundingMode: .awayFromZero) | ||
} | ||
|
||
} | ||
|
||
extension Decimal192 { | ||
public var clamped: Self { | ||
decimalClampedToZero(decimal: self) | ||
} | ||
|
||
public func isNegative() -> Bool { | ||
decimalIsNegative(decimal: self) | ||
} | ||
} | ||
|
||
extension Decimal192: Comparable { | ||
public static func > (lhs: Self, rhs: Self) -> Bool { | ||
lhs.greaterThan(other: rhs) | ||
} | ||
public static func < (lhs: Self, rhs: Self) -> Bool { | ||
lhs.lessThan(other: rhs) | ||
} | ||
public static func >= (lhs: Self, rhs: Self) -> Bool { | ||
lhs.greaterThanOrEqual(other: rhs) | ||
} | ||
public static func <= (lhs: Self, rhs: Self) -> Bool { | ||
lhs.lessThanOrEqual(other: rhs) | ||
} | ||
} | ||
extension Decimal192 { | ||
|
||
public func lessThan(other: Self) -> Bool { | ||
decimalLessThan(lhs: self, rhs: other) | ||
} | ||
|
||
public func lessThanOrEqual(other: Self) -> Bool { | ||
decimalLessThanOrEqual(lhs: self, rhs: other) | ||
} | ||
|
||
public func greaterThan(other: Self) -> Bool { | ||
decimalGreaterThan(lhs: self, rhs: other) | ||
} | ||
|
||
public func greaterThanOrEqual(other: Self) -> Bool { | ||
decimalGreaterThanOrEqual(lhs: self, rhs: other) | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
apple/Sources/Sargon/Extensions/Methods/DisplayName+Wrap+Functions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
extension DisplayName { | ||
public init(validating name: String) throws { | ||
self = try newDisplayName(name: name) | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
apple/Sources/Sargon/Extensions/Methods/Mnemonic+Wrap+Functions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
extension Mnemonic { | ||
public var phrase: String { | ||
mnemonicPhrase(from: self) | ||
} | ||
} |
File renamed without changes.
12 changes: 9 additions & 3 deletions
12
apple/Sources/Sargon/Extensions/Swiftified/AppearanceID+Swiftified.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
public typealias AppearanceID = AppearanceId | ||
|
||
extension AppearanceID: Sendable {} | ||
extension AppearanceID: CaseIterable { | ||
public static var allCases: [Self] { | ||
appearanceIdsAll() | ||
extension AppearanceID: Identifiable { | ||
public typealias ID = UInt8 | ||
public var id: ID { | ||
value | ||
} | ||
} | ||
extension AppearanceID: CustomStringConvertible { | ||
public var description: String { | ||
value.description | ||
} | ||
} |
3 changes: 0 additions & 3 deletions
3
apple/Sources/Sargon/Extensions/Swiftified/BagOfBytes+Random.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 54 additions & 10 deletions
64
apple/Sources/Sargon/Extensions/Swiftified/Decimal192+Swiftified.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,55 @@ | ||
extension Decimal192: Sendable {} | ||
//extension Decimal192: ExpressibleByStringLiteral { | ||
// | ||
//} | ||
//extension Decimal192: ExpressibleByFloatLiteral { | ||
// | ||
//} | ||
//extension Decimal192: SignedNumeric /* Numeric, ExpressibleByIntegerLiteral AdditiveArithmetic */ | ||
//{ | ||
// | ||
//} | ||
|
||
extension Decimal192: ExpressibleByStringLiteral { | ||
public init(stringLiteral string: String) { | ||
try! self.init(string) | ||
} | ||
} | ||
extension Decimal192: ExpressibleByIntegerLiteral { | ||
public init(integerLiteral i64: Int64) { | ||
self = newDecimalFromI64(value: i64) | ||
} | ||
} | ||
|
||
|
||
extension Decimal192: AdditiveArithmetic { | ||
public static var zero: Self { | ||
newDecimalFromU64(value: 0) | ||
} | ||
public static func + (lhs: Self, rhs: Self) -> Self { | ||
decimalAdd(lhs: lhs, rhs: rhs) | ||
} | ||
public static func - (lhs: Self, rhs: Self) -> Self { | ||
decimalSub(lhs: lhs, rhs: rhs) | ||
} | ||
} | ||
extension Decimal192: SignedNumeric { | ||
public prefix static func - (operand: Self) -> Self { | ||
decimalNeg(decimal: operand) | ||
} | ||
} | ||
extension Decimal192: Numeric { | ||
public typealias Magnitude = Self | ||
|
||
public var magnitude: Magnitude { | ||
decimalAbs(decimal: self) | ||
} | ||
|
||
public static func * (lhs: Self, rhs: Self) -> Self { | ||
decimalMul(lhs: lhs, rhs: rhs) | ||
} | ||
|
||
public static func *= (lhs: inout Self, rhs: Self) { | ||
lhs = lhs * rhs | ||
} | ||
|
||
public init?<T>(exactly source: T) where T: BinaryInteger { | ||
if let i64 = Int64(exactly: source) { | ||
self = newDecimalFromI64(value: i64) | ||
} else if let u64 = UInt64(exactly: source) { | ||
self = newDecimalFromU64(value: u64) | ||
} else { | ||
return nil | ||
} | ||
} | ||
} |
5 changes: 0 additions & 5 deletions
5
apple/Sources/Sargon/Extensions/Swiftified/DisplayName+Swiftified.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
apple/Sources/Sargon/Extensions/Swiftified/LocaleConfig+Swiftified.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
extension LocaleConfig: Sendable {} | ||
extension LocaleConfig { | ||
public init(locale: Locale) { | ||
self.init( | ||
decimalSeparator: locale.decimalSeparator, | ||
groupingSeparator: locale.groupingSeparator | ||
) | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
apple/Sources/Sargon/Extensions/Swiftified/Mnemonic+Swiftified.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
extension Mnemonic: Sendable {} |
Oops, something went wrong.