Skip to content

Commit

Permalink
Merge pull request #9 from ensan-hcl/refactoring/concurrency
Browse files Browse the repository at this point in the history
Add Sendable Conformances
  • Loading branch information
ensan-hcl authored Aug 2, 2023
2 parents f1fdf0a + fb0c73d commit 856682b
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Sources/KanaKanjiConverterModule/CIDData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

public enum CIDData {
public enum CIDData: Sendable {
static var totalCount: Int {
1319
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/KanaKanjiConverterModule/Candidate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ struct CandidateData {
}
}

public enum CompleteAction {
public enum CompleteAction: Sendable {
/// カーソルを調整する
case moveCursor(Int)
}

/// 変換候補のデータ
public struct Candidate {
public struct Candidate: Sendable {
/// 入力となるテキスト
public var text: String
/// 評価値
Expand Down
4 changes: 2 additions & 2 deletions Sources/KanaKanjiConverterModule/ComposingText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import SwiftUtils
/// のようになる。`
/// カーソルのポジションもこのクラスが管理する。
/// 設計方針として、inputStyleに関わる実装の違いは全てアップデート方法の違いとして吸収し、`input` / `delete` / `moveCursor` / `complete`時の違いとしては露出させないようにすることを目指した。
public struct ComposingText {
public struct ComposingText: Sendable {
public init(convertTargetCursorPosition: Int = 0, input: [ComposingText.InputElement] = [], convertTarget: String = "") {
self.convertTargetCursorPosition = convertTargetCursorPosition
self.input = input
Expand All @@ -29,7 +29,7 @@ public struct ComposingText {
public private(set) var convertTarget: String = ""

/// ユーザ入力の単位
public struct InputElement {
public struct InputElement: Sendable {
/// 入力された文字
public var character: Character
/// そのときの入力方式(ローマ字入力 / ダイレクト入力)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

public struct ConvertRequestOptions {
public struct ConvertRequestOptions: Sendable {
/// 変換リクエストに必要な設定データ
///
/// - parameters:
Expand Down Expand Up @@ -91,7 +91,7 @@ public struct ConvertRequestOptions {
)
}

public struct Metadata {
public struct Metadata: Sendable {
/// - parameters:
/// - appVersionString: アプリのバージョンを指定します。このデータは`KanaKanjiCovnerter.toVersionCandidate(_:)`などで用いられます。
public init(appVersionString: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

public struct DicdataElement: Equatable, Hashable {
public struct DicdataElement: Equatable, Hashable, Sendable {
static let BOSData = Self(word: "", ruby: "", cid: CIDData.BOS.cid, mid: MIDData.BOS.mid, value: 0, adjust: 0)
static let EOSData = Self(word: "", ruby: "", cid: CIDData.EOS.cid, mid: MIDData.EOS.mid, value: 0, adjust: 0)

Expand Down
2 changes: 1 addition & 1 deletion Sources/KanaKanjiConverterModule/MIDData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

public enum MIDData {
public enum MIDData: Sendable {
static var totalCount: Int {
503
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/KanaKanjiConverterModule/Replacer/TextReplacer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public struct TextReplacer {
return results
}

public struct SearchResultItem {
public struct SearchResultItem: Sendable {
public var query: String
public var text: String
public var inputable: Bool {
Expand Down Expand Up @@ -113,7 +113,7 @@ public struct TextReplacer {
}
}

public struct ReplacementCandidate {
public struct ReplacementCandidate: Sendable {
public var target: String
public var replace: String
public var base: String
Expand Down
8 changes: 4 additions & 4 deletions Sources/KanaKanjiConverterModule/States.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by ensan on 2023/04/30.
//

public enum InputStyle: String {
public enum InputStyle: String, Sendable {
/// 入力された文字を直接入力するスタイル
case direct = "direct"
/// ローマ字日本語入力とするスタイル
Expand All @@ -19,7 +19,7 @@ public enum KeyboardLanguage: String, Codable, Equatable, Sendable {
case none
}

public enum LearningType: Int, CaseIterable {
public enum LearningType: Int, CaseIterable, Sendable {
case inputAndOutput
case onlyOutput
case nothing
Expand All @@ -33,13 +33,13 @@ public enum LearningType: Int, CaseIterable {
}
}

public enum ConverterBehaviorSemantics {
public enum ConverterBehaviorSemantics: Sendable {
/// 標準的な日本語入力のように、変換する候補を選ぶパターン
case conversion
/// iOSの英語入力のように、確定は不要だが、左右の文字列の置き換え候補が出てくるパターン
case replacement([ReplacementTarget])

public enum ReplacementTarget: UInt8 {
public enum ReplacementTarget: UInt8, Sendable {
case emoji
}
}
18 changes: 9 additions & 9 deletions Sources/KanaKanjiConverterModule/TemplateData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation
import SwiftUtils

public struct TemplateData: Codable {
public struct TemplateData: Codable, Sendable {
public var name: String
public var literal: any TemplateLiteralProtocol
public var type: TemplateLiteralType
Expand Down Expand Up @@ -92,13 +92,13 @@ public struct TemplateData: Codable {
}
}

public protocol TemplateLiteralProtocol {
public protocol TemplateLiteralProtocol: Sendable {
func export() -> String

func previewString() -> String
}

public enum TemplateLiteralType {
public enum TemplateLiteralType: Sendable {
case date
case random
}
Expand All @@ -113,7 +113,7 @@ public extension TemplateLiteralProtocol {
}
}

public struct DateTemplateLiteral: TemplateLiteralProtocol, Equatable {
public struct DateTemplateLiteral: TemplateLiteralProtocol, Equatable, Sendable {
public init(format: String, type: DateTemplateLiteral.CalendarType, language: DateTemplateLiteral.Language, delta: String, deltaUnit: Int) {
self.format = format
self.type = type
Expand All @@ -129,7 +129,7 @@ public struct DateTemplateLiteral: TemplateLiteralProtocol, Equatable {
public var delta: String
public var deltaUnit: Int

public enum CalendarType: String {
public enum CalendarType: String, Sendable {
case western
case japanese

Expand All @@ -143,7 +143,7 @@ public struct DateTemplateLiteral: TemplateLiteralProtocol, Equatable {
}
}

public enum Language: String {
public enum Language: String, Sendable {
case english = "en_US"
case japanese = "ja_JP"

Expand Down Expand Up @@ -183,7 +183,7 @@ public struct DateTemplateLiteral: TemplateLiteralProtocol, Equatable {
}
}

public struct RandomTemplateLiteral: TemplateLiteralProtocol, Equatable {
public struct RandomTemplateLiteral: TemplateLiteralProtocol, Equatable, Sendable {
public init(value: RandomTemplateLiteral.Value) {
self.value = value
}
Expand All @@ -192,12 +192,12 @@ public struct RandomTemplateLiteral: TemplateLiteralProtocol, Equatable {
lhs.value == rhs.value
}

public enum ValueType: String {
public enum ValueType: String, Sendable {
case int
case double
case string
}
public enum Value: Equatable {
public enum Value: Equatable, Sendable {
case int(from: Int, to: Int)
case double(from: Double, to: Double)
case string([String])
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftUtils/AppVersion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Foundation
/// It is initialized with a string that represents a version of an app.
/// The string must be in the format of "major.minor.patch".
/// The string must not contain any other characters than numbers and dots.
public struct AppVersion: Codable, Equatable, Comparable, Hashable, LosslessStringConvertible, CustomStringConvertible {
public struct AppVersion: Codable, Equatable, Comparable, Hashable, LosslessStringConvertible, CustomStringConvertible, Sendable {

/// ParseError is an enum that represents an error that occurs when parsing a string to an AppVersion.
private enum ParseError: Error {
Expand Down

0 comments on commit 856682b

Please sign in to comment.