Skip to content

Commit

Permalink
better abstractions for service
Browse files Browse the repository at this point in the history
  • Loading branch information
ypopovych committed Nov 19, 2023
1 parent f68a6f2 commit c1c4220
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Sources/TesseractService/Tesseract.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public final class Tesseract: TesseractBase {
return self
}

public func transport<T: Transport>(_ transport: T) -> Self {
public func transport<T: CoreTransportConvertible>(_ transport: T) -> Self {
tesseract = tesseract_service_add_transport(&tesseract, transport.toCore())
return self
}
Expand Down
8 changes: 8 additions & 0 deletions Sources/TesseractTransportsService/CoreTransport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public final class CoreTransportProcessor: TransportProcessor {
}
}

public protocol CoreTransportConvertible {
func toCore() -> ServiceTransport
}

extension ServiceTransport: CSwiftAnyDropPtr {}

extension ServiceTransport {
Expand All @@ -43,6 +47,10 @@ extension ServiceTransport {
}
}

extension ServiceTransport: CoreTransportConvertible {
public func toCore() -> ServiceTransport { self }
}

extension Transport {
public func toCore() -> ServiceTransport {
ServiceTransport(transport: self)
Expand Down
2 changes: 1 addition & 1 deletion Sources/TesseractTransportsService/Transport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public protocol TransportProcessor: AnyObject {

public protocol BoundTransport: AnyObject {}

public protocol Transport: AnyObject {
public protocol Transport: CoreTransportConvertible, AnyObject {
func bind(processor: TransportProcessor) -> BoundTransport
}

0 comments on commit c1c4220

Please sign in to comment.