feat: add `ArtifactId::identifier()` (#1087)

* feat: add `ArtifactId::identifier()`

* docs: note that `slug` is not unique

* chore: remove --all from clippy

Co-authored-by: Georgios Konstantopoulos <me@gakonst.com>
This commit is contained in:
Bjerg 2022-03-28 18:42:48 +02:00 committed by GitHub
parent 967a142563
commit 7842a70803
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -126,7 +126,7 @@ jobs:
- name: cargo fmt - name: cargo fmt
run: cargo +nightly-2022-03-20 fmt --all -- --check run: cargo +nightly-2022-03-20 fmt --all -- --check
- name: cargo clippy - name: cargo clippy
run: cargo +nightly-2022-03-20 clippy --all --all-features -- -D warnings run: cargo +nightly-2022-03-20 clippy --all-features -- -D warnings
wasm: wasm:
name: WASM name: WASM

View File

@ -36,9 +36,18 @@ pub struct ArtifactId {
impl ArtifactId { impl ArtifactId {
/// Returns a <filename>:<name> slug that identifies an artifact /// Returns a <filename>:<name> slug that identifies an artifact
///
/// Note: This identifier is not necessarily unique. If two contracts have the same name, they
/// will share the same slug. For a unique identifier see [ArtifactId::identifier].
pub fn slug(&self) -> String { pub fn slug(&self) -> String {
format!("{}.json:{}", self.path.file_stem().unwrap().to_string_lossy(), self.name) format!("{}.json:{}", self.path.file_stem().unwrap().to_string_lossy(), self.name)
} }
/// Returns a <source path>:<name> slug that uniquely identifies an artifact
pub fn identifier(&self) -> String {
format!("{}:{}", self.source.to_string_lossy(), self.name)
}
/// Returns a <filename><version>:<name> slug that identifies an artifact /// Returns a <filename><version>:<name> slug that identifies an artifact
pub fn slug_versioned(&self) -> String { pub fn slug_versioned(&self) -> String {
format!( format!(