Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider generating a struct, or otherwise simplify usage #80

Open
jaskij opened this issue Feb 22, 2022 · 2 comments
Open

Consider generating a struct, or otherwise simplify usage #80

jaskij opened this issue Feb 22, 2022 · 2 comments
Assignees
Labels
enhancement New feature or request features features high higj level

Comments

@jaskij
Copy link

jaskij commented Feb 22, 2022

TL;DR: make it easier to write shared code interfacing shadow's output.

Currently, shadow only generates pub const VAR: &str variables - it's great as is, but is also quite a bit unwieldy, leading to a lot of boilerplate in multi-binary projects.

There are two main benefits to this approach:

  • easier manipulation and code decoupling - if I want to write display methods, I could have functions accepting a reference to that struct
  • API documentation is easier - just look up said structure

This also ties into what @epage wrote in #75 (comment) - such a struct would work as an accessor. Or rather, structs, as it would be then split per-source (git, rust, etc).

In my project I have a struct (not using all variables), which could easily be made as a part of code generation, like this:

pub struct BuildInfo {
    pub version_major: &'static str,
    pub version_minor: &'static str,
    pub version_patch: &'static str,
    pub version_pre: &'static str,
    pub git_commit_hash: &'static str,
    pub git_short_hash: &'static str,
    pub git_clean: bool,
    pub build_type: &'static str,
    pub cargo_version: &'static str,
    pub rust_version: &'static str,
    pub rust_channel: &'static str,
    pub target: &'static str,
}

which is then initialized with:

pub(crate) const BUILD_INFO: BuildInfo = BuildInfo {
    version_major: PKG_VERSION_MAJOR,
    version_minor: PKG_VERSION_MINOR,
    version_patch: PKG_VERSION_PATCH,
    version_pre: PKG_VERSION_PRE,
    git_commit_hash: COMMIT_HASH,
    git_short_hash: SHORT_COMMIT,
    git_clean: GIT_CLEAN,
    build_type: BUILD_RUST_CHANNEL,
    cargo_version: CARGO_VERSION,
    rust_version: RUST_VERSION,
    rust_channel: RUST_CHANNEL,
    target: BUILD_TARGET,
};
@baoyachi
Copy link
Owner

That's a good suggestion. I'll think about it. @jaskij THX.

@baoyachi baoyachi added the features features label Mar 10, 2022
@baoyachi baoyachi self-assigned this Jun 22, 2022
@baoyachi baoyachi added enhancement New feature or request high higj level labels Jun 22, 2022
@baoyachi baoyachi pinned this issue Jun 22, 2022
@baoyachi baoyachi unpinned this issue Nov 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request features features high higj level
Projects
None yet
Development

No branches or pull requests

2 participants