Bootstrap geth Rust workspace
This commit is contained in:
commit
26f81ff1ef
73 changed files with 4835 additions and 0 deletions
10
crates/geth-types/Cargo.toml
Normal file
10
crates/geth-types/Cargo.toml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
[package]
|
||||
name = "geth-types"
|
||||
version = "0.1.0"
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
[dependencies]
|
||||
serde.workspace = true
|
||||
thiserror.workspace = true
|
||||
132
crates/geth-types/src/lib.rs
Normal file
132
crates/geth-types/src/lib.rs
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt::{Display, Formatter};
|
||||
|
||||
macro_rules! string_id {
|
||||
($name:ident) => {
|
||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
|
||||
pub struct $name(String);
|
||||
|
||||
impl $name {
|
||||
#[must_use]
|
||||
pub fn new(value: impl Into<String>) -> Self {
|
||||
Self(value.into())
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn as_str(&self) -> &str {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for $name {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_str(&self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for $name {
|
||||
fn from(value: String) -> Self {
|
||||
Self(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for $name {
|
||||
fn from(value: &str) -> Self {
|
||||
Self(value.to_owned())
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
string_id!(AgentId);
|
||||
string_id!(UserId);
|
||||
string_id!(DeviceId);
|
||||
string_id!(NodeId);
|
||||
string_id!(MemberId);
|
||||
string_id!(GroupId);
|
||||
string_id!(ResourceId);
|
||||
string_id!(ResourceName);
|
||||
string_id!(PrincipalId);
|
||||
string_id!(Capability);
|
||||
string_id!(BlobHash);
|
||||
string_id!(DocumentId);
|
||||
string_id!(KvId);
|
||||
string_id!(DbId);
|
||||
string_id!(PipeId);
|
||||
string_id!(TopicId);
|
||||
string_id!(AuthOpId);
|
||||
string_id!(KeyId);
|
||||
string_id!(SecretId);
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
|
||||
pub struct UnixMillis(pub i64);
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum ResourceKind {
|
||||
Db,
|
||||
Kv,
|
||||
Pipe,
|
||||
Document,
|
||||
Pubsub,
|
||||
Cas,
|
||||
SshProxy,
|
||||
}
|
||||
|
||||
impl ResourceKind {
|
||||
#[must_use]
|
||||
pub fn as_str(&self) -> &'static str {
|
||||
match self {
|
||||
Self::Db => "db",
|
||||
Self::Kv => "kv",
|
||||
Self::Pipe => "pipe",
|
||||
Self::Document => "document",
|
||||
Self::Pubsub => "pubsub",
|
||||
Self::Cas => "cas",
|
||||
Self::SshProxy => "ssh-proxy",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for ResourceKind {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_str(self.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
impl std::str::FromStr for ResourceKind {
|
||||
type Err = TypeParseError;
|
||||
|
||||
fn from_str(value: &str) -> Result<Self, Self::Err> {
|
||||
match value {
|
||||
"db" => Ok(Self::Db),
|
||||
"kv" => Ok(Self::Kv),
|
||||
"pipe" => Ok(Self::Pipe),
|
||||
"document" => Ok(Self::Document),
|
||||
"pubsub" => Ok(Self::Pubsub),
|
||||
"cas" => Ok(Self::Cas),
|
||||
"ssh-proxy" | "ssh" => Ok(Self::SshProxy),
|
||||
_ => Err(TypeParseError::UnknownResourceKind(value.to_owned())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum TypeParseError {
|
||||
#[error("unknown resource kind: {0}")]
|
||||
UnknownResourceKind(String),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
|
||||
#[serde(tag = "kind", content = "id", rename_all = "kebab-case")]
|
||||
pub enum Principal {
|
||||
AdminKey(KeyId),
|
||||
User(UserId),
|
||||
Device(DeviceId),
|
||||
Node(NodeId),
|
||||
Agent(AgentId),
|
||||
IrohEndpoint(String),
|
||||
Group(GroupId),
|
||||
Resource(ResourceId),
|
||||
BearerSecret(SecretId),
|
||||
}
|
||||
Loading…
Reference in a new issue