//! Common builder types shared across all builders //! //! Generates the Set, Unset, IsSet, IsUnset types that all builders use. //! These are generated once per crate and re-used by all builders. use proc_macro2::TokenStream; use quote::quote; /// Generate the common builder types module /// /// This should be generated once at the root of the generated code /// (e.g., in lib.rs or a builder_types module). pub fn generate_common_types() -> TokenStream { quote! { /// Marker type indicating a builder field has been set pub struct Set(pub T); impl Set { /// Extract the inner value #[inline] pub fn into_inner(self) -> T { self.0 } } /// Marker type indicating a builder field has not been set pub struct Unset; /// Trait indicating a builder field is set (has a value) #[rustversion::attr( since(1.78.0), diagnostic::on_unimplemented( message = "the field `{Self}` was not set, but this method requires it to be set", label = "the field `{Self}` was not set" ) )] pub trait IsSet: private::Sealed {} /// Trait indicating a builder field is unset (no value yet) #[rustversion::attr( since(1.78.0), diagnostic::on_unimplemented( message = "the field `{Self}` was already set, but this method requires it to be unset", label = "the field `{Self}` was already set" ) )] pub trait IsUnset: private::Sealed {} impl IsSet for Set {} impl IsUnset for Unset {} mod private { /// Sealed trait to prevent external implementations pub trait Sealed {} impl Sealed for super::Set {} impl Sealed for super::Unset {} } } }