feat: Working on node builder
This commit is contained in:
27
Sources/CliDoc/Nodes/AnyNode.swift
Normal file
27
Sources/CliDoc/Nodes/AnyNode.swift
Normal file
@@ -0,0 +1,27 @@
|
||||
public struct AnyNode: NodeRepresentable {
|
||||
@usableFromInline
|
||||
let node: any NodeRepresentable
|
||||
|
||||
@inlinable
|
||||
public init<N: NodeRepresentable>(@NodeBuilder _ build: () -> N) {
|
||||
self.node = build()
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public init<N: NodeRepresentable>(_ node: N) {
|
||||
self.node = node
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public func render() -> String {
|
||||
node.render()
|
||||
}
|
||||
}
|
||||
|
||||
public extension NodeRepresentable {
|
||||
|
||||
@inlinable
|
||||
func eraseToAnyNode() -> AnyNode {
|
||||
.init(self)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user