Skip to content

Testing with a sqlx database #283

Answered by ilslv
pbevin asked this question in Q&A
May 15, 2023 · 1 comments · 3 replies
Discussion options

You must be logged in to vote

@pbevin alternatively the book also describes a way to use custom World constructors that actually can be async:

TIP: Using Default::default() for constructing a World object may be not enough. In such case a custom constructor may be specified via #[world(init = my_constructor)] attribute.

#[derive(Debug, World)]
// Accepts both sync/async and fallible/infallible functions.
#[world(init = Self::new)] 
pub struct AnimalWorld {
    cat: Cat,
}

impl AnimalWorld {
    fn new() -> Self {
        Self {
            cat: Cat { hungry: true }
        }
    }
}

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@pbevin
Comment options

@ilslv
Comment options

Answer selected by pbevin
@pbevin
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants