Crates.io | darling-api |
lib.rs | darling-api |
version | 0.1.4 |
source | src |
created_at | 2024-04-08 17:41:17.419021 |
updated_at | 2024-04-12 01:43:40.518533 |
description | Library API for darling |
homepage | |
repository | |
max_upload_size | |
id | 1200753 |
size | 11,196 |
Note: darling-api is still pre-1.0, and breaking changes will occur. Consider very carefully if you actually want to implement an API that will certainly have breaking changes in the near future and require updates.
darling-api
is the library crate that allows custom implementations of darling. Darling is designed to specifically be extendible without changing darling itself, so that anyone can implement it for their package manager without having to contribute to darling itself. This API provides the necessary capabilities to implement darling.
This API can be implemented either by modifying a pre-existing template, or by creating a new crate from scratch. The template is recommended due to some quirks about naming, but you're free to start from scratch if you understand how to implement it correctly.
darling-template provides a starting point for implementing darling. To use it, first set the template up onto your local machine:
Open the repository and click "Use this template > Create a new repository". This will set up a git repo that you can clone onto your local machine and begin development with git immediately.
If you don't want to make a git repository for your project right now, you can just clone the template to get it onto your local machine.
Next, rename the struct and implement the missing methods. Read the documentation for each method carefully to understand what it must do and not do. Do not rename the global PACKAGE_MANAGER
variable.
Edit your crate name in Cargo.toml
, and ensure it starts with darling-
, such as darling-npm
or darling-vscode
. Publish your crate when it's done!
That's it! once your crate is published, it can be used by anyone with darling, no updates required.
Alternatively, you can start from scratch and create a module without using a template. The process is as follows:
darling-
(technically darling_
is also allowed, but not the convention). For example, cargo new darling-example --lib
. Ensure that your name isn't taken on crates.io.darling-api
to your dependencies with cargo add darling-api
.darling::PackageManager
.
get_name()
function returns a consistent value on all calls, and that it does not return "module". module
is a built-in reserved name used by darling to manage itself. Also, it should be unique to other darling modules, or else they will be incompatible. It is convention to make it the name of your crate, without the darling-
prefix. For example, the `darlingpub static
variable of your struct with the name PACKAGE_MANAGER
that is accessible from your crate root.crates.io
with cargo publish