8000 GitHub - code-trust/cfg-stub · GitHub
[go: up one dir, main page]

Skip to content
code-trustPublic

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

 

History

8 Commits

Folders and files

Repository files navigation

cfg-stub

Proc macros that replace function and impl method bodies with unimplemented!() when a feature is disabled, so you keep one impl without hand-written stubs.

Example

#[cfg_attr(not(feature = "sqlx"), cfg_stub::methods)]
impl UserStore {
    async fn get(&self, id: u64) -> Option<User> {
        sqlx::query_as!(User, "SELECT … WHERE id = $1", id)
            .fetch_optional(&self.pool)
            .await
            .unwrap()
    }
}

With sqlx off, every method body becomes unimplemented!(). With sqlx on, your code runs as written.

#[cfg_attr(not(feature = "sqlx"), cfg_stub::function)] works the same on free functions.

License

MIT

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0