Skip to content

API muesli fluent projectable

Felix Jones edited this page Jan 15, 2026 · 1 revision

muesli/fluent/projectable

Defined in header <muesli/fluent/projectable>

projector_codec

template<ValueType>
struct projector_codec

Forward declaration of apply_codec

Member Functions

member

Binds this codec to a member of a struct

Creates a member_codec that automatically extracts/injects the field from/to the owner struct during encode/decode operations.

template<auto MemberPtr> constexpr auto member() const noexcept

Returns: A member_codec<Derived, MemberPtr> wrapping this codec

Example:

struct Record { int id; };
auto id_codec = int32_codec.member<&Record::id>();
Record rec{42};
auto encoded = id_codec.encode(rec);

project

Projects this codec from an owner type using a custom projector

Creates a projector_codec with custom encode/decode transformation logic. Allows flexible field extraction and reconstruction.

template<typename Owner, typename Projector> constexpr auto project(Projector proj) const noexcept

Parameters:

  • proj — The projector function

Returns: A projector_codec wrapping this codec

Related


member_codec

struct member_codec

Forward declaration of member_codec

Member Functions

member

Binds this codec to a member of a struct

Creates a member_codec that automatically extracts/injects the field from/to the owner struct during encode/decode operations.

template<auto MemberPtr> constexpr auto member() const noexcept

Returns: A member_codec<Derived, MemberPtr> wrapping this codec

Example:

struct Record { int id; };
auto id_codec = int32_codec.member<&Record::id>();
Record rec{42};
auto encoded = id_codec.encode(rec);

project

Projects this codec from an owner type using a custom projector

Creates a projector_codec with custom encode/decode transformation logic. Allows flexible field extraction and reconstruction.

template<typename Owner, typename Projector> constexpr auto project(Projector proj) const noexcept

Parameters:

  • proj — The projector function

Returns: A projector_codec wrapping this codec


projectable

template<Derived>
struct projectable

Mixin providing .member<>() and .project<>() for member/projection codecs

This mixin provides two methods for adapting codecs to structured data:

  • .member<&T::field>(): Bind this codec to a specific member of a struct
  • .project(projector): Project from an owner type via custom transformation

Used for:

  • Struct field serialisation
  • Custom value extraction/injection
  • Computed/derived field handling

Member Functions

member

Binds this codec to a member of a struct

Creates a member_codec that automatically extracts/injects the field from/to the owner struct during encode/decode operations.

template<auto MemberPtr> constexpr auto member() const noexcept

Returns: A member_codec<Derived, MemberPtr> wrapping this codec

Example:

struct Record { int id; };
auto id_codec = int32_codec.member<&Record::id>();
Record rec{42};
auto encoded = id_codec.encode(rec);

project

Projects this codec from an owner type using a custom projector

Creates a projector_codec with custom encode/decode transformation logic. Allows flexible field extraction and reconstruction.

template<typename Owner, typename Projector> constexpr auto project(Projector proj) const noexcept

Parameters:

  • proj — The projector function

Returns: A projector_codec wrapping this codec

Related


member

template<auto MemberPtr> constexpr auto member() const noexcept

Binds this codec to a member of a struct

Creates a member_codec that automatically extracts/injects the field from/to the owner struct during encode/decode operations.

Template Parameters

Parameter Description
MemberPtr A pointer-to-member of form &OwnerType::memberName

Returns: A member_codec<Derived, MemberPtr> wrapping this codec

Example

struct Record { int id; };
auto id_codec = int32_codec.member<&Record::id>();
Record rec{42};
auto encoded = id_codec.encode(rec);

project

template<typename Owner, typename Projector> constexpr auto project(Projector proj) const noexcept

Projects this codec from an owner type using a custom projector

Creates a projector_codec with custom encode/decode transformation logic. Allows flexible field extraction and reconstruction.

Template Parameters

Parameter Description
Owner The owner type from which to project
Projector A callable that takes const Owner& and returns the member value

Parameters

  • proj — The projector function

Returns: A projector_codec wrapping this codec


Clone this wiki locally