Skip to content

Add CanFinalizeWithDefault method for partial records#130

Merged
soareschen merged 1 commit intomainfrom
finalize-with-default
Jul 20, 2025
Merged

Add CanFinalizeWithDefault method for partial records#130
soareschen merged 1 commit intomainfrom
finalize-with-default

Conversation

@soareschen
Copy link
Collaborator

@soareschen soareschen commented Jul 20, 2025

Example as asked on Reddit:

use cgp::core::field::CanFinalizeWithDefault;
use cgp::prelude::*;

#[derive(Default)]
pub struct Uuid;

#[derive(Default)]
pub struct ItemType;

#[derive(Default)]
pub struct EquipmentType;

#[derive(Default)]
pub struct ItemQuantity(pub u64);

#[derive(BuildField)]
pub struct Item {
    pub id: Uuid,
    pub name: String,
    pub item_type: ItemType,
    pub equipment_type: EquipmentType,
    pub maximum_quantity: ItemQuantity,
}

#[test]
fn test_default_construction() {
    let item = Item::builder()
        .build_field(PhantomData::<symbol!("name")>, "my-item".to_owned())
        .build_field(
            PhantomData::<symbol!("maximum_quantity")>,
            ItemQuantity(100),
        )
        .finalize_with_default();
}

@soareschen soareschen merged commit 3c49f28 into main Jul 20, 2025
5 checks passed
@soareschen soareschen deleted the finalize-with-default branch July 20, 2025 03:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant