chore: Add in some more files for the testing of the sdk and the rust interface

This commit is contained in:
J H
2024-03-13 16:23:24 -06:00
parent ba325b1581
commit b6fe0be1b2
46 changed files with 451 additions and 116 deletions

View File

@@ -27,12 +27,12 @@ lazy_static::lazy_static! {
pub static ref SYSTEM_ID: Id = Id(InternedString::intern("x_system"));
}
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
pub struct Id(InternedString);
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Default, ts_rs::TS)]
pub struct Id(#[ts(type = "string")] InternedString);
impl TryFrom<InternedString> for Id {
type Error = InvalidId;
fn try_from(value: InternedString) -> Result<Self, Self::Error> {
if ID_REGEX.is_match(&*value) {
if ID_REGEX.is_match(&value) {
Ok(Id(value))
} else {
Err(InvalidId)
@@ -52,7 +52,7 @@ impl TryFrom<String> for Id {
impl TryFrom<&str> for Id {
type Error = InvalidId;
fn try_from(value: &str) -> Result<Self, Self::Error> {
if ID_REGEX.is_match(&value) {
if ID_REGEX.is_match(value) {
Ok(Id(InternedString::intern(value)))
} else {
Err(InvalidId)
@@ -67,7 +67,7 @@ impl From<Id> for InternedString {
impl std::ops::Deref for Id {
type Target = str;
fn deref(&self) -> &Self::Target {
&*self.0
&self.0
}
}
impl std::fmt::Display for Id {
@@ -77,7 +77,7 @@ impl std::fmt::Display for Id {
}
impl AsRef<str> for Id {
fn as_ref(&self) -> &str {
&*self.0
&self.0
}
}
impl Borrow<str> for Id {
@@ -99,7 +99,7 @@ impl Serialize for Id {
where
Ser: Serializer,
{
serializer.serialize_str(&*self)
serializer.serialize_str(self)
}
}
impl<'q> sqlx::Encode<'q, sqlx::Postgres> for Id {