mirror of
https://seed.radicle.dev/rad:z6cFWeWpnZNHh9rUW8phgA3b5yGt.git
synced 2026-11-13 15:00:47 +08:00
ref-format: improve Qualified/NamespacedPattern API
Some elements of the `QaulifiedPattern` and `NamespacedPattern` API were missing: - `From` implementations - `Display` implementations - `Serialize` and `Deserialize` implementations - `qualified_pattern` macro This also requires bumping versions: - `git-ref-format`: 0.3.1 - `git-ref-core`: 0.3.1 - `git-ref-format-macro`: 0.3.1 - `radicle-git-ext`: 0.8.1 - `radicle-surf`: 0.22.1 Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com> X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
@@ -166,3 +166,35 @@ pub fn pattern(input: TokenStream) -> TokenStream {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a [`git_ref_format_core::refspec::QualifiedPattern`] from a string
|
||||
/// literal.
|
||||
///
|
||||
/// The string is validated at compile time, and an unsafe conversion is
|
||||
/// emitted.
|
||||
#[proc_macro_error]
|
||||
#[proc_macro]
|
||||
pub fn qualified_pattern(input: TokenStream) -> TokenStream {
|
||||
let lit = parse_macro_input!(input as LitStr);
|
||||
let val = lit.value();
|
||||
|
||||
let parsed: Result<&PatternStr, Error> = val.as_str().try_into();
|
||||
match parsed {
|
||||
Ok(safe) => {
|
||||
let safe: &str = safe.as_str();
|
||||
let expand = quote! {
|
||||
unsafe {
|
||||
use ::std::mem::transmute;
|
||||
use ::radicle_git_ext::ref_format::refspec::QualifiedPattern;
|
||||
|
||||
transmute::<_, QualifiedPattern>(#safe.to_owned())
|
||||
}
|
||||
};
|
||||
TokenStream::from(expand)
|
||||
}
|
||||
|
||||
Err(e) => {
|
||||
abort!(lit.span(), "invalid refspec pattern literal: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user