Skip to content

Argument validation in builders #34

@geeknoid

Description

@geeknoid

We should describe the best way to handle fallible methods on builders:

struct FooBuilder;

impl FooBuilder {
    // value must be > 1 and < 128
    fn max_size(self, value: usize) -> Self {
    }
}

Should max_size return a Result instead?

    fn max_size(self, value: usize) -> Result<Self>

Or should we introduce a newtype that captures the constraints:

    fn max_size(self, value: FooSize) -> Self

Or should the max_size API accept any value, and just have the final build() method return a Result?

Metadata

Metadata

Assignees

Labels

requestAsks for a guideline on a topic.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions