Skip to content

How to make invalid state irrepresentable? #7

@musjj

Description

@musjj

I'm noticing that the models come with constructors like this:

impl Author {
pub fn new(id: uuid::Uuid, name: AuthorName, email: EmailAddress) -> Self {
Self { id, name, email }
}

Which is later used by the db implementation:

Ok(Author::new(
author_id,
req.name().clone(),
req.email().clone(),
))

But this means that consumers can construct potentially invalid Authors that aren't necessarily backed by the db.

Not sure if there's a good solution here, since you need to allow foreign modules to construct Author with the repository trait.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions