diff --git a/include/rfl/capnproto/to_schema.hpp b/include/rfl/capnproto/to_schema.hpp index ea429110..d5819540 100644 --- a/include/rfl/capnproto/to_schema.hpp +++ b/include/rfl/capnproto/to_schema.hpp @@ -7,13 +7,13 @@ #include "../Literal.hpp" #include "../Processors.hpp" +#include "../Result.hpp" #include "../SnakeCaseToCamelCase.hpp" #include "../Variant.hpp" #include "../json.hpp" #include "../parsing/schema/Type.hpp" #include "../parsing/schema/ValidationType.hpp" #include "../parsing/schema/make.hpp" -#include "Reader.hpp" #include "Schema.hpp" #include "Writer.hpp" #include "schema/Type.hpp" @@ -23,14 +23,26 @@ namespace rfl::capnproto { std::string to_string_representation( const parsing::schema::Definition& internal_schema); +template +struct SchemaHolder { + rfl::Result> schema_; + static SchemaHolder make() noexcept { + const auto internal_schema = + parsing::schema::make>(); + const auto str = to_string_representation(internal_schema); + return SchemaHolder{Schema::from_string(str)}; + } +}; + +template +static const SchemaHolder schema_holder = + SchemaHolder::make(); + /// Returns the Cap'n Proto schema for a class. template -Schema to_schema() noexcept { - const auto internal_schema = - parsing::schema::make>(); - const auto str = to_string_representation(internal_schema); - return Schema::from_string(str).value(); +Schema to_schema() { + return schema_holder.schema_.value(); } } // namespace rfl::capnproto