Skip to content

Allow optional fields for types that implement Default #6

@mmastrac

Description

@mmastrac

I think that requiring fields that have a valid default makes the API awkward. ie, the below code should be allowed.

EDIT: I just noticed that #[builder(default = ...)] exists, but that seems like overkill when optional makes the most sense. Perhaps #[builder(optional)] could be inferred to always be #[builder(default = "Default::default()"]?

/// Represents a configuration schema object (type definition)
#[derive(Debug, Clone, Serialize, Deserialize, Builder)]
pub struct ConfigSchemaObject {
    /// Name of the type (e.g., "cfg::Config", "cfg::Auth")
    #[builder(required)]
    pub name: String,
    /// List of ancestor type IDs
    #[builder(optional)]
    pub ancestors: Vec<ConfigSchemaTypeReference>,
    /// Properties of this type
    #[builder(required)]
    pub properties: Vec<ConfigSchemaProperty>,
    /// Links (relationships) to other types
    #[builder(required)]
    pub links: Vec<ConfigSchemaLink>,
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions