magnetar/magnetar_sdk/src/lib.rs

93 lines
1.8 KiB
Rust
Raw Normal View History

use serde::{Deserialize, Serialize};
2023-11-02 19:40:12 +00:00
use std::ops::{Deref, DerefMut};
use ts_rs::TS;
2023-10-25 17:45:59 +00:00
pub use magnetar_mmm_parser as mmm;
2023-08-04 10:28:35 +00:00
pub mod endpoints;
pub mod types;
pub mod util_types;
2023-08-04 10:28:35 +00:00
2023-11-02 19:40:12 +00:00
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
#[repr(transparent)]
pub struct Required<T>(pub T);
2023-08-04 10:28:35 +00:00
2023-11-02 19:40:12 +00:00
impl<T: TS + 'static> TS for Required<T> {
const EXPORT_TO: Option<&'static str> = None;
fn decl() -> String {
unimplemented!()
}
fn name() -> String {
T::name()
}
fn inline() -> String {
T::name()
}
fn inline_flattened() -> String {
unimplemented!()
}
fn dependencies() -> Vec<ts_rs::Dependency> {
ts_rs::Dependency::from_ty::<T>().into_iter().collect()
}
fn transparent() -> bool {
false
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
#[repr(transparent)]
pub struct Optional<T>(pub Option<T>);
impl<T: TS + 'static> TS for Optional<T> {
const EXPORT_TO: Option<&'static str> = None;
fn decl() -> String {
unimplemented!()
}
fn name() -> String {
T::name()
}
fn inline() -> String {
format!("Partial<{}>", T::name())
}
fn inline_flattened() -> String {
unimplemented!()
}
fn dependencies() -> Vec<ts_rs::Dependency> {
ts_rs::Dependency::from_ty::<T>().into_iter().collect()
}
fn transparent() -> bool {
false
}
}
impl<T: TS> Deref for Optional<T> {
type Target = Option<T>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<T: TS> DerefMut for Optional<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
pub trait Packed: 'static {
type Input: 'static;
2023-08-04 10:28:35 +00:00
fn pack_from(val: Self::Input) -> Self;
2023-08-04 10:28:35 +00:00
}