feat: Moves core functionality into it's own library.
This commit is contained in:
21
Sources/CliDocCore/Nodes/AnyTextNode.swift
Normal file
21
Sources/CliDocCore/Nodes/AnyTextNode.swift
Normal file
@@ -0,0 +1,21 @@
|
||||
/// A type-erased text node.
|
||||
public struct AnyTextNode: TextNode {
|
||||
@usableFromInline
|
||||
let makeString: () -> String
|
||||
|
||||
@inlinable
|
||||
public init<N: TextNode>(_ node: N) {
|
||||
self.makeString = node.render
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public var body: some TextNode { makeString() }
|
||||
}
|
||||
|
||||
public extension TextNode {
|
||||
|
||||
@inlinable
|
||||
func eraseToAnyTextNode() -> AnyTextNode {
|
||||
AnyTextNode(self)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user