Struct hakari::HakariCargoToml[][src]

pub struct HakariCargoToml { /* fields omitted */ }
Expand description

Support for maintaining Cargo.toml files that unify features in a workspace.

This struct maintains a context around a Cargo.toml file. It provides facilities for diffing the contents of the file, and for writing out new contents.

Structure of the Cargo.toml file

The Cargo.toml file is treated as partially generated. It is expected to have a section marked off as, for example:

[package]
...

## BEGIN HAKARI SECTION
[dependencies]
...

[build-dependencies]
...

[dev-dependencies]
...
## END HAKARI SECTION

The part of the Cargo.toml file between the BEGIN HAKARI SECTION and END HAKARI SECTION lines is managed by this struct, and changes to it may not be preserved. The part of the file outside this section can be edited and its contents will be preserved.

Setting up a new package

For Hakari to manage a package, a bit of initial prep work must be done:

  1. Add a new library package in a desired location within your workspace, for example: cargo new --lib hakari-package.

  2. Copy and paste the following lines of code to the end of the package’s Cargo.toml file. Be sure to put in a trailing newline.

    ## BEGIN HAKARI SECTION
    
    ## END HAKARI SECTION
    
  3. Add an empty build.rs file (the exact contents don’t matter, but the presence of this file makes build dependencies work properly).

    fn main() {}

Implementations

The string "\n### BEGIN HAKARI SECTION\n". This string marks the beginning of the generated section.

The string "\n### END HAKARI SECTION\n". This string marks the end of the generated section.

Creates a new instance of HakariCargoToml with the Cargo.toml located at the given path. Reads the contents of the file off of disk.

If the path is relative, it is evaluated with respect to the current directory.

Returns an error if the file couldn’t be read (other than if the file wasn’t found, which is a case handled by this struct).

Creates a new instance of HakariCargoToml at the given workspace root and crate directory. Reads the contents of the file off of disk.

This is a convenience method around appending crate_dir and Cargo.toml to workspace_root.

If the path is relative, it is evaluated with respect to the current directory.

Creates a new instance of HakariCargoToml with the given path with the given contents as read from disk.

This may be useful for test scenarios.

Returns the toml path provided at construction time.

Returns the contents of the file on disk as read at construction time.

Returns the start and end offsets of the part of the file treated as generated.

Returns the part of the file that is treated as generated.

This part of the file will be replaced on write.

Returns true if the contents on disk are different from the provided TOML output.

Computes the diff between the contents on disk and the provided TOML output.

This returns a diffy::Patch, which can be formatted through methods provided by diffy. diffy is re-exported at the top level of this crate.

Examples

TODO

Writes out the provided TOML to the generated section of the file. The rest of the file is left unmodified.

self is consumed because the contents of the file are now assumed to be invalid.

Returns true if the contents were different and the file was written out, false if the contents were the same and the file was not written out, and an error if there was an issue while writing the file out.

Writes out the full contents, including the provided TOML, to the given writer.

Writes out the full contents, including the provided TOML, to the given fmt::Write instance.

std::io::Write expects bytes to be written to it, so using it with a &mut String is inconvenient. This alternative is more convenient, and also works for fmt::Formatter instances.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.