Merge pull request #4650 from gitbutlerapp/add-reference-name-struct

derive some useful traits for tagged string and reference name
This commit is contained in:
Kiril Videlov 2024-08-08 15:11:26 +02:00 committed by GitHub
commit ee7660f395
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 2 additions and 0 deletions

View File

@ -26,6 +26,7 @@ pub fn normalize_branch_name(name: &str) -> anyhow::Result<String> {
Ok(result) Ok(result)
} }
#[derive(Default, Debug, Clone, PartialEq, Eq, Hash)]
pub struct _ReferenceName; pub struct _ReferenceName;
/// The name of a reference i.e. `refs/heads/master` /// The name of a reference i.e. `refs/heads/master`
pub type ReferenceName = TaggedString<_ReferenceName>; pub type ReferenceName = TaggedString<_ReferenceName>;

View File

@ -3,6 +3,7 @@ use std::{fmt, marker::PhantomData, ops::Deref};
use serde::{Deserialize, Deserializer, Serialize, Serializer}; use serde::{Deserialize, Deserializer, Serialize, Serializer};
/// Tagged string is designed to clarify the purpose of strings when used as a return type /// Tagged string is designed to clarify the purpose of strings when used as a return type
#[derive(Default, Clone, PartialEq, Eq, Hash)]
pub struct TaggedString<T>(String, PhantomData<T>); pub struct TaggedString<T>(String, PhantomData<T>);
impl<T> From<String> for TaggedString<T> { impl<T> From<String> for TaggedString<T> {