Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import Foundation
/// This allows decoding a ``RenderSection`` into its appropriate concrete type, based on the section's
/// ``RenderSection/kind``.
public struct CodableContentSection: Codable, Equatable {
var section: any RenderSection {
public var section: any RenderSection {
@storageRestrictions(initializes: typeErasedSection)
init(initialValue) {
typeErasedSection = AnyRenderSection(initialValue)
}
get {
typeErasedSection.value
}
Expand All @@ -27,15 +31,13 @@ public struct CodableContentSection: Codable, Equatable {

/// Creates a codable content section from the given section.
public init(_ section: any RenderSection) {
self.typeErasedSection = AnyRenderSection(section)
self.section = section
}

public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let kind = try container.decode(RenderSectionKind.self, forKey: .kind)

self.typeErasedSection = AnyRenderSection(ContentRenderSection(kind: .content, content: []))
switch kind {
case .discussion:
section = try ContentRenderSection(from: decoder)
Expand Down