Skip to content

Commit

Permalink
Remove datatype reexport in root
Browse files Browse the repository at this point in the history
  • Loading branch information
oscartbeaumont committed Jul 31, 2024
1 parent aadc2b3 commit 4b15269
Show file tree
Hide file tree
Showing 45 changed files with 148 additions and 117 deletions.
14 changes: 7 additions & 7 deletions specta-datatype-from/src/data_type_from/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ pub fn derive(input: proc_macro::TokenStream) -> syn::Result<proc_macro::TokenSt
let struct_name = ident.to_string();
quote! {
#[automatically_derived]
impl From<#ident> for #crate_ref::StructType {
fn from(t: #ident) -> #crate_ref::StructType {
impl From<#ident> for #crate_ref::datatype::StructType {
fn from(t: #ident) -> #crate_ref::datatype::StructType {
#crate_ref::internal::construct::r#struct(#struct_name.into(), None, vec![], #crate_ref::internal::construct::struct_named(vec![#(#fields),*], None))
}
}

#[automatically_derived]
impl From<#ident> for #crate_ref::DataType {
fn from(t: #ident) -> #crate_ref::DataType {
impl From<#ident> for #crate_ref::datatype::DataType {
fn from(t: #ident) -> #crate_ref::datatype::DataType {
Self::Struct(t.into())
}
}
Expand All @@ -96,16 +96,16 @@ pub fn derive(input: proc_macro::TokenStream) -> syn::Result<proc_macro::TokenSt
fields[0].clone()
} else {
quote! {
#crate_ref::DataType::Tuple(#crate_ref::internal::construct::tuple(
#crate_ref::datatype::DataType::Tuple(#crate_ref::internal::construct::tuple(
vec![#(#fields),*]
))
}
};

quote! {
#[automatically_derived]
impl From<#ident> for #crate_ref::DataType {
fn from(t: #ident) -> #crate_ref::DataType {
impl From<#ident> for #crate_ref::datatype::DataType {
fn from(t: #ident) -> #crate_ref::datatype::DataType {
#implementation
}
}
Expand Down
2 changes: 1 addition & 1 deletion specta-go/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
html_favicon_url = "https://github.com/oscartbeaumont/specta/raw/main/.github/logo-128.png"
)]

use specta::{DataType, Generics, Type, TypeMap};
use specta::{datatype::DataType, Generics, Type, TypeMap};

/// TODO
pub fn export<T: Type>() -> Result<String, String> {
Expand Down
5 changes: 4 additions & 1 deletion specta-kotlin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
html_favicon_url = "https://github.com/oscartbeaumont/specta/raw/main/.github/logo-128.png"
)]

use specta::{DataType, Generics, PrimitiveType, Type, TypeMap};
use specta::{
datatype::{DataType, PrimitiveType},
Generics, Type, TypeMap,
};

/// TODO
pub fn export<T: Type>() -> Result<String, String> {
Expand Down
4 changes: 2 additions & 2 deletions specta-macros/src/type/attr/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ impl CommonAttr {
) -> proc_macro2::TokenStream {
match &self.deprecated {
Some(DeprecatedType::Deprecated) => {
quote!(Some(#crate_ref::DeprecatedType::Deprecated))
quote!(Some(#crate_ref::datatype::DeprecatedType::Deprecated))
}
Some(DeprecatedType::DeprecatedWithSince { since, note }) => {
let since = since
.as_ref()
.map(|v| quote!(#v.into()))
.unwrap_or(quote!(None));

quote!(Some(#crate_ref::DeprecatedType::DeprecatedWithSince {
quote!(Some(#crate_ref::datatype::DeprecatedType::DeprecatedWithSince {
since: #since,
note: #note.into(),
}))
Expand Down
12 changes: 6 additions & 6 deletions specta-macros/src/type/enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,25 +205,25 @@ pub fn parse_enum(

let (repr, can_flatten) = match repr {
Tagged::Untagged => (
quote!(#crate_ref::EnumRepr::Untagged),
quote!(#crate_ref::datatype::EnumRepr::Untagged),
data.variants
.iter()
.any(|v| matches!(&v.fields, Fields::Unit | Fields::Named(_))),
),
Tagged::Externally => (
quote!(#crate_ref::EnumRepr::External),
quote!(#crate_ref::datatype::EnumRepr::External),
data.variants.iter().any(|v| match &v.fields {
Fields::Unnamed(f) if f.unnamed.len() == 1 => true,
Fields::Named(_) => true,
_ => false,
}),
),
Tagged::Adjacently { tag, content } => (
quote!(#crate_ref::EnumRepr::Adjacent { tag: #tag.into(), content: #content.into() }),
quote!(#crate_ref::datatype::EnumRepr::Adjacent { tag: #tag.into(), content: #content.into() }),
true,
),
Tagged::Internally { tag } => (
quote!(#crate_ref::EnumRepr::Internal { tag: #tag.into() }),
quote!(#crate_ref::datatype::EnumRepr::Internal { tag: #tag.into() }),
data.variants
.iter()
.any(|v| matches!(&v.fields, Fields::Unit | Fields::Named(_))),
Expand All @@ -233,10 +233,10 @@ pub fn parse_enum(
let skip_bigint_checs = enum_attrs.unstable_skip_bigint_checks;

Ok((
quote!(#crate_ref::DataType::Enum(#crate_ref::internal::construct::r#enum(#name.into(), #sid, #repr, #skip_bigint_checs, vec![#(#definition_generics),*], vec![#(#variant_types),*]))),
quote!(#crate_ref::datatype::DataType::Enum(#crate_ref::internal::construct::r#enum(#name.into(), #sid, #repr, #skip_bigint_checs, vec![#(#definition_generics),*], vec![#(#variant_types),*]))),
quote!({
let generics = vec![#(#reference_generics),*];
#crate_ref::reference::reference::<Self>(type_map, #crate_ref::internal::construct::data_type_reference(
#crate_ref::datatype::reference::reference::<Self>(type_map, #crate_ref::internal::construct::data_type_reference(
#name.into(),
#sid,
generics
Expand Down
2 changes: 1 addition & 1 deletion specta-macros/src/type/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ pub fn construct_datatype(
let type_ident = type_ident.to_string();
let generics = generics(
&crate_ref,

Check warning on line 192 in specta-macros/src/type/generics.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-macros/src/type/generics.rs:192:17 | 192 | &crate_ref, | ^^^^^^^^^^ help: change this to: `crate_ref` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

Check warning on line 192 in specta-macros/src/type/generics.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-macros/src/type/generics.rs:192:17 | 192 | &crate_ref, | ^^^^^^^^^^ help: change this to: `crate_ref` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
quote!(&[#crate_ref::DataType::Generic(std::borrow::Cow::Borrowed(#type_ident).into())]),
quote!(&[#crate_ref::datatype::DataType::Generic(std::borrow::Cow::Borrowed(#type_ident).into())]),
);
return Ok(quote! {
let #var_ident = generics.get(#i).cloned().unwrap_or_else(
Expand Down
10 changes: 5 additions & 5 deletions specta-macros/src/type/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ pub fn derive(input: proc_macro::TokenStream) -> syn::Result<proc_macro::TokenSt
Ok(quote! {
const _: () = {
const IMPL_LOCATION: #crate_ref::ImplLocation = #impl_location;
const DEFINITION_GENERICS: &[#crate_ref::DataType] = &[#(#definition_generics),*];
const DEFINITION_GENERICS: &[#crate_ref::datatype::DataType] = &[#(#definition_generics),*];

#[automatically_derived]
#type_impl_heading {
fn inline(type_map: &mut #crate_ref::TypeMap, generics: #crate_ref::Generics) -> #crate_ref::DataType {
fn inline(type_map: &mut #crate_ref::TypeMap, generics: #crate_ref::Generics) -> #crate_ref::datatype::DataType {
let generics = match generics {
#crate_ref::Generics::Definition => DEFINITION_GENERICS,
#crate_ref::Generics::Provided(generics) => generics,
Expand All @@ -147,7 +147,7 @@ pub fn derive(input: proc_macro::TokenStream) -> syn::Result<proc_macro::TokenSt
#inlines
}

fn reference(type_map: &mut #crate_ref::TypeMap, generics: &[#crate_ref::DataType]) -> #crate_ref::reference::Reference {
fn reference(type_map: &mut #crate_ref::TypeMap, generics: &[#crate_ref::datatype::DataType]) -> #crate_ref::datatype::reference::Reference {
#reference
}
}
Expand All @@ -158,7 +158,7 @@ pub fn derive(input: proc_macro::TokenStream) -> syn::Result<proc_macro::TokenSt
#sid
}

fn named_data_type(type_map: &mut #crate_ref::TypeMap, generics: &[#crate_ref::DataType]) -> #crate_ref::NamedDataType {
fn named_data_type(type_map: &mut #crate_ref::TypeMap, generics: &[#crate_ref::datatype::DataType]) -> #crate_ref::datatype::NamedDataType {
#crate_ref::internal::construct::named_data_type(
#name.into(),
#comments.into(),
Expand All @@ -169,7 +169,7 @@ pub fn derive(input: proc_macro::TokenStream) -> syn::Result<proc_macro::TokenSt
)
}

fn definition_named_data_type(type_map: &mut #crate_ref::TypeMap) -> #crate_ref::NamedDataType {
fn definition_named_data_type(type_map: &mut #crate_ref::TypeMap) -> #crate_ref::datatype::NamedDataType {
#crate_ref::internal::construct::named_data_type(
#name.into(),
#comments.into(),
Expand Down
8 changes: 4 additions & 4 deletions specta-macros/src/type/struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub fn parse_struct(
}
});
let reference_generics =
quote!(let generics: &[#crate_ref::DataType] = &[#(#reference_generics),*];);
quote!(let generics: &[#crate_ref::datatype::DataType] = &[#(#reference_generics),*];);

let reference_generics2 = generic_idents.iter().map(|(i, ident)| {
let ident_str = ident.to_string();
Expand Down Expand Up @@ -266,18 +266,18 @@ pub fn parse_struct(
Fields::Unit => quote!(#crate_ref::internal::construct::struct_unit()),
};

quote!(#crate_ref::DataType::Struct(#crate_ref::internal::construct::r#struct(#name.into(), Some(#sid), vec![#(#definition_generics),*], #fields)))
quote!(#crate_ref::datatype::DataType::Struct(#crate_ref::internal::construct::r#struct(#name.into(), Some(#sid), vec![#(#definition_generics),*], #fields)))
};

let category = if container_attrs.inline {
quote!({
#reference_generics
#crate_ref::reference::inline::<Self>(type_map, generics)
#crate_ref::datatype::reference::inline::<Self>(type_map, generics)
})
} else {
quote!({
#reference_generics
#crate_ref::reference::reference::<Self>(type_map, #crate_ref::internal::construct::data_type_reference(
#crate_ref::datatype::reference::reference::<Self>(type_map, #crate_ref::internal::construct::data_type_reference(
#name.into(),
#sid,
vec![#(#reference_generics2),*]
Expand Down
2 changes: 1 addition & 1 deletion specta-openapi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use openapiv3::{
ArrayType, BooleanType, NumberType, ReferenceOr, Schema, SchemaData, SchemaKind, StringType,
Type,
};
use specta::{DataType, PrimitiveType};
use specta::datatype::{DataType, PrimitiveType};

// pub fn to_openapi_export(def: &DataType) -> Result<openapiv3::Schema, String> {
// Ok(match &def {
Expand Down
2 changes: 1 addition & 1 deletion specta-rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
html_favicon_url = "https://github.com/oscartbeaumont/specta/raw/main/.github/logo-128.png"
)]

use specta::{DataType, Generics, Type, TypeMap};
use specta::{datatype::DataType, Generics, Type, TypeMap};

/// TODO
pub fn export<T: Type>() -> Result<String, String> {
Expand Down
6 changes: 4 additions & 2 deletions specta-serde/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ use std::collections::HashSet;
use thiserror::Error;

use specta::{
datatype::{
DataType, EnumRepr, EnumType, EnumVariants, LiteralType, PrimitiveType, StructFields,
},
internal::{resolve_generics, skip_fields, skip_fields_named},
DataType, EnumRepr, EnumType, EnumVariants, LiteralType, PrimitiveType, SpectaID, StructFields,
TypeMap,
SpectaID, TypeMap,
};

// TODO: The error should show a path to the type causing the issue like the BigInt error reporting.
Expand Down
5 changes: 4 additions & 1 deletion specta-swift/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
html_favicon_url = "https://github.com/oscartbeaumont/specta/raw/main/.github/logo-128.png"
)]

use specta::{DataType, Generics, PrimitiveType, Type, TypeMap};
use specta::{
datatype::{DataType, PrimitiveType},
Generics, Type, TypeMap,
};

/// TODO
pub fn export<T: Type>() -> Result<String, String> {
Expand Down
5 changes: 4 additions & 1 deletion specta-typescript/src/js_doc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::borrow::Borrow;

use specta::{DeprecatedType, GenericType, TypeMap};
use specta::{
datatype::{DeprecatedType, GenericType},
TypeMap,
};
use typescript::CommentFormatterArgs;

use super::*;
Expand Down
10 changes: 5 additions & 5 deletions specta-typescript/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ pub use error::*;
use reserved_terms::*;
pub use typescript::*;

use specta::{
internal::{detect_duplicate_type_names, skip_fields, skip_fields_named, NonSkipField},
DataType, DeprecatedType, FunctionResultVariant, Generics, NamedDataType, NamedType,
PrimitiveType, Type, TypeMap,
use specta::datatype::{
DataType, DeprecatedType, EnumRepr, EnumType, EnumVariant, EnumVariants, FunctionResultVariant,
LiteralType, NamedDataType, PrimitiveType, StructFields, StructType, TupleType,
};
use specta::{
EnumRepr, EnumType, EnumVariant, EnumVariants, LiteralType, StructFields, StructType, TupleType,
internal::{detect_duplicate_type_names, skip_fields, skip_fields_named, NonSkipField},
Generics, NamedType, Type, TypeMap,
};
use specta_serde::is_valid_ty;

Expand Down
7 changes: 6 additions & 1 deletion specta-typescript/src/typescript.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{borrow::Cow, io, path::PathBuf};

use specta::{DeprecatedType, Language, TypeMap};
use specta::{datatype::DeprecatedType, Language, TypeMap};
use specta_serde::is_valid_ty;

use crate::{comments, detect_duplicate_type_names, export_named_datatype, ExportError};
Expand Down Expand Up @@ -76,6 +76,11 @@ impl Default for Typescript {
}

impl Typescript {
/// Construct a new Typescript exporter with the default options configured.
pub fn new() -> Self {
Default::default()
}

/// Configure a header for the file.
///
/// This is perfect for configuring lint ignore rules or other file-level comments.
Expand Down
2 changes: 1 addition & 1 deletion specta-util/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{
sync::{Mutex, OnceLock, PoisonError},
};

use specta::{NamedDataType, NamedType, SpectaID, TypeMap};
use specta::{datatype::NamedDataType, NamedType, SpectaID, TypeMap};

use crate::TypeCollection;

Expand Down
2 changes: 1 addition & 1 deletion specta-util/src/static_types.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::fmt::Debug;

use specta::{DataType, Generics, Type, TypeMap};
use specta::{datatype::DataType, Generics, Type, TypeMap};

/// Easily convert a non-Specta type into a Specta compatible type.
/// This will be typed as `any` in Typescript.
Expand Down
2 changes: 1 addition & 1 deletion specta-util/src/type_collection.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{borrow::Borrow, collections::HashMap, path::Path};

use specta::{Language, NamedDataType, NamedType, SpectaID, TypeMap};
use specta::{datatype::NamedDataType, Language, NamedType, SpectaID, TypeMap};

/// Define a set of types which can be exported together
#[derive(Debug, Clone, PartialEq, Eq)]
Expand Down
1 change: 1 addition & 0 deletions specta-zod/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mod export_config;

use context::{ExportContext, PathItem};
use specta::{
datatype::*,
internal::{detect_duplicate_type_names, skip_fields, skip_fields_named, NonSkipField},
*,
};
Expand Down
7 changes: 3 additions & 4 deletions specta/src/datatype/enum.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::borrow::Cow;

use crate::{
datatype::DataType, DeprecatedType, GenericType, NamedDataType, NamedFields, SpectaID,
UnnamedFields,
};
use crate::SpectaID;

use super::{DataType, DeprecatedType, GenericType, NamedDataType, NamedFields, UnnamedFields};

/// Enum type which dictates how the enum is represented.
///
Expand Down
2 changes: 1 addition & 1 deletion specta/src/datatype/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::borrow::Cow;

use crate::{DataType, DeprecatedType};
use super::{DataType, DeprecatedType};

#[derive(Debug, Clone, PartialEq)]
pub struct Field {
Expand Down
2 changes: 1 addition & 1 deletion specta/src/datatype/function.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::borrow::Cow;

use crate::{DataType, DeprecatedType};
use super::{DataType, DeprecatedType};

/// Contains type information about a function annotated with [`specta`](macro@crate::specta).
/// Returned by [`fn_datatype`].
Expand Down
2 changes: 1 addition & 1 deletion specta/src/datatype/list.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::DataType;
use super::DataType;

#[derive(Debug, Clone, PartialEq)]
pub struct List {
Expand Down
2 changes: 1 addition & 1 deletion specta/src/datatype/literal.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::DataType;
use super::DataType;

/// Type of a literal value for things like const generics.
///
Expand Down
2 changes: 1 addition & 1 deletion specta/src/datatype/map.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::DataType;
use super::DataType;

#[derive(Debug, Clone, PartialEq)]

Expand Down
4 changes: 3 additions & 1 deletion specta/src/datatype/named.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::borrow::Cow;

use crate::{DataType, DeprecatedType, ImplLocation, SpectaID};
use crate::ImplLocation;

use super::{DataType, DeprecatedType, SpectaID};

/// A NamedDataTypeImpl includes extra information which is only available for [NamedDataType]'s that come from a real Rust type.
#[derive(Debug, Clone, PartialEq)]
Expand Down
2 changes: 1 addition & 1 deletion specta/src/datatype/primitive.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::DataType;
use super::DataType;

/// Type of primitives like numbers and strings.
#[allow(non_camel_case_types)]
Expand Down
Loading

0 comments on commit 4b15269

Please sign in to comment.