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 using cargo-util-schemas instead of cargo_toml #1361

Open
musicinmybrain opened this issue Jul 5, 2024 · 2 comments
Open

Consider using cargo-util-schemas instead of cargo_toml #1361

musicinmybrain opened this issue Jul 5, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@musicinmybrain
Copy link
Contributor

musicinmybrain commented Jul 5, 2024

Summary 💡

As suggested in a Fedora package review, you might consider replacing the cargo_toml crate with cargo-util-schemas (plus toml). While cargo-util-schemas doesn’t have as much high-level functionality as cargo_toml, it seems like it should be adequate for what onefetch-manifest needs.

Motivation 🔦

The advantage of cargo-util-schemas is that it is the official implementation of serialization and deserialization schemas used by cargo itself, so if you use it, you can be confident that your Cargo.toml support remains consistent with cargo‘s.

@musicinmybrain musicinmybrain added the enhancement New feature or request label Jul 5, 2024
@musicinmybrain
Copy link
Contributor Author

The beginning of this could look something like

    let data = std::fs::read_to_string(path)?;
    let m: cargo_util_schemas::manifest::TomlManifest = toml::from_str(&data)?;

and then perhaps

    let package = *m.package.context("Not a package (only a workspace)")?;
    let description = package.description.map(|v| v.as_value().cloned()).flatten();

but after that there are decisions and/or slightly more invasive changes to be made. In particular, cargo_toml claims a package always has a version, but in cargo-util-schemas the version field is an Option<…>, which is inconsistent with the current definition of onefetch_manifest::Manifest:

#[derive(Clone, PartialEq, Eq, Debug)]
pub struct Manifest {
pub manifest_type: ManifestType,
pub number_of_dependencies: usize,
pub name: String,
pub description: Option<String>,
pub version: String,
pub license: Option<String>,
}

@spenserblack
Copy link
Collaborator

spenserblack commented Jul 5, 2024

If you'd like, feel free to submit a PR 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants