Compare commits

..

2 commits

Author SHA1 Message Date
b5de7d55e9 WIP: add more tests to repo-actor crate
All checks were successful
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
2024-06-16 08:02:16 +01:00
2e71e40378 refactor: add newtype macro
All checks were successful
Rust / build (push) Successful in 1m18s
ci/woodpecker/cron/cron-docker-builder Pipeline was successful
ci/woodpecker/cron/push-next Pipeline was successful
ci/woodpecker/cron/tag-created Pipeline was successful
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
2024-06-16 08:00:00 +01:00
2 changed files with 58 additions and 0 deletions

View file

@ -8,6 +8,7 @@ mod forge_name;
mod forge_type; mod forge_type;
pub mod git_dir; pub mod git_dir;
mod host_name; mod host_name;
mod newtype;
mod registered_webhook; mod registered_webhook;
mod repo_alias; mod repo_alias;
mod repo_branches; mod repo_branches;

View file

@ -0,0 +1,57 @@
//
#[macro_export]
macro_rules! newtype {
($name:ident is a $type:ty, without Display) => {
#[derive(
Clone,
Default,
Debug,
derive_more::From,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash,
derive_more::AsRef,
derive_more::Deref,
serde::Deserialize,
serde::Serialize,
)]
pub struct $name($type);
impl $name {
pub fn new(value: impl Into<$type>) -> Self {
Self(value.into())
}
pub fn unwrap(self) -> $type {
self.0
}
}
};
($name:ident is a $type:ty) => {
#[derive(
Clone,
Default,
Debug,
derive_more::Display,
derive_more::From,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash,
derive_more::AsRef,
derive_more::Deref,
serde::Deserialize,
serde::Serialize,
)]
pub struct $name($type);
impl $name {
pub fn new(value: impl Into<$type>) -> Self {
Self(value.into())
}
pub fn unwrap(self) -> $type {
self.0
}
}
};
}