Skip to content

Commit

Permalink
Drop DataType::Result + impl Type for Result
Browse files Browse the repository at this point in the history
  • Loading branch information
oscartbeaumont committed Jul 13, 2024
1 parent 13fd87c commit 9c41ff0
Show file tree
Hide file tree
Showing 8 changed files with 0 additions and 65 deletions.
1 change: 0 additions & 1 deletion specta-rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ fn datatype(t: &DataType) -> Result<String, String> {
// TODO: Serde serialize + deserialize on types

Ok(match t {
DataType::Result(_) => todo!(),
DataType::Unknown => todo!(),

Check warning on line 20 in specta-rust/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

`todo` should not be present in production code

warning: `todo` should not be present in production code --> specta-rust/src/lib.rs:20:30 | 20 | DataType::Unknown => todo!(), | ^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#todo = note: requested on the command line with `-W clippy::todo`
DataType::Any => "serde_json::Value".to_owned(),
DataType::Primitive(ty) => ty.to_rust_str().to_owned(),
Expand Down
6 changes: 0 additions & 6 deletions specta-serde/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ fn is_valid_ty_internal(
is_valid_ty_internal(ty, type_map, checked_references)?;
}
}
DataType::Result(ty) => {
is_valid_ty_internal(&ty.0, type_map, checked_references)?;
is_valid_ty_internal(&ty.1, type_map, checked_references)?;
}
DataType::Reference(ty) => {
for (_, generic) in ty.generics() {
is_valid_ty_internal(generic, type_map, checked_references)?;
Expand Down Expand Up @@ -237,8 +233,6 @@ fn validate_internally_tag_enum_datatype(
},
// `()` is `null` and is valid
DataType::Tuple(ty) if ty.elements().is_empty() => {}
// Are valid as they are serialized as an map-type. Eg. `"Ok": 5` or `"Error": "todo"`
DataType::Result(_) => {}
// References need to be checked against the same rules.
DataType::Reference(ty) => {
let ty = type_map.get(ty.sid()).expect("Type was never populated"); // TODO: Error properly
Expand Down
17 changes: 0 additions & 17 deletions specta-typescript/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,22 +387,6 @@ pub(crate) fn datatype_inner(
)?
}
DataType::Tuple(tuple) => s.push_str(&tuple_datatype(ctx, tuple, type_map)?),
DataType::Result(result) => {
let mut variants = vec![
{
let mut v = String::new();
datatype_inner(ctx.clone(), &result.0, type_map, &mut v)?;
v
},
{
let mut v = String::new();
datatype_inner(ctx, &result.1, type_map, &mut v)?;
v
},
];
variants.dedup();
s.push_str(&variants.join(" | "));
}
DataType::Reference(reference) => match &reference.generics()[..] {
[] => s.push_str(&reference.name()),

Check warning on line 391 in specta-typescript/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

warning: this expression creates a reference which is immediately dereferenced by the compiler --> specta-typescript/src/lib.rs:391:30 | 391 | [] => s.push_str(&reference.name()), | ^^^^^^^^^^^^^^^^^ help: change this to: `reference.name()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
generics => {
Expand Down Expand Up @@ -897,7 +881,6 @@ fn validate_type_for_tagged_intersection(
| DataType::Nullable(_)
| DataType::List(_)
| DataType::Map(_)
| DataType::Result(_)
| DataType::Generic(_) => Ok(false),
DataType::Literal(v) => match v {
LiteralType::None => Ok(true),
Expand Down
13 changes: 0 additions & 13 deletions specta-zod/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,18 +254,6 @@ pub(crate) fn datatype_inner(ctx: ExportContext, typ: &DataType, type_map: &Type
)?
}
DataType::Tuple(tuple) => tuple_datatype(ctx, tuple, type_map)?,
DataType::Result(result) => {
let mut variants = vec![
datatype_inner(ctx.clone(), &result.0, type_map)?,
datatype_inner(ctx, &result.1, type_map)?,
];
variants.dedup();
if variants.len() == 1 {
variants.pop().expect("Vec is not empty")
} else {
format!("z.union([{}])", variants.join(", "))
}
}
DataType::Reference(reference) => match &reference.generics()[..] {
[] => reference.name().to_string(),
_generics => {
Expand Down Expand Up @@ -736,7 +724,6 @@ fn validate_type_for_tagged_intersection(
| DataType::Nullable(_)
| DataType::List(_)
| DataType::Map(_)
| DataType::Result(_)
| DataType::Generic(_) => Ok(false),
DataType::Literal(v) => match v {
LiteralType::None => Ok(true),
Expand Down
2 changes: 0 additions & 2 deletions specta/src/datatype/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ pub enum DataType {
Struct(StructType),
Enum(EnumType),
Tuple(TupleType),
// Result
Result(Box<(DataType, DataType)>),
// A reference type that has already been defined
Reference(DataTypeReference),
Generic(GenericType),
Expand Down
7 changes: 0 additions & 7 deletions specta/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,6 @@ pub fn resolve_generics(mut dt: DataType, generics: &Vec<(GenericType, DataType)

dt
}
DataType::Result(result) => DataType::Result(Box::new({
let (ok, err) = *result;
(
resolve_generics(ok, generics),
resolve_generics(err, generics),
)
})),
DataType::Reference(ref mut r) => {
for (_, generic) in r.generics.iter_mut() {
*generic = resolve_generics(generic.clone(), generics);
Expand Down
1 change: 0 additions & 1 deletion specta/src/internal/interop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,6 @@ pub fn specta_v2_to_v1(datatype: DataType) -> specta1::DataType {
fields: t.elements.into_iter().map(specta_v2_to_v1).collect(),
generics: vec![],
}),
DataType::Result(_) => panic!("Specta v1 does not support Result types"),
DataType::Reference(r) => specta1::DataType::Reference(specta1::DataTypeReference {
name: match r.name {
Cow::Borrowed(v) => v,
Expand Down
18 changes: 0 additions & 18 deletions specta/src/type/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,24 +171,6 @@ impl<T: Type> Type for Option<T> {
}
}

impl<T: Type, E: Type> Type for std::result::Result<T, E> {
fn inline(type_map: &mut TypeMap, generics: Generics) -> DataType {
DataType::Result(Box::new((
T::inline(type_map, generics),
E::inline(type_map, generics),
)))
}

fn reference(type_map: &mut TypeMap, generics: &[DataType]) -> Reference {
Reference {
inner: DataType::Result(Box::new((
T::reference(type_map, generics).inner,
E::reference(type_map, generics).inner,
))),
}
}
}

impl<T> Type for std::marker::PhantomData<T> {
fn inline(_: &mut TypeMap, _: Generics) -> DataType {
DataType::Literal(LiteralType::None)
Expand Down

0 comments on commit 9c41ff0

Please sign in to comment.