Skip to content

Commit

Permalink
fixes #163
Browse files Browse the repository at this point in the history
  • Loading branch information
oscartbeaumont committed Nov 22, 2023
1 parent 3a3f4bf commit 5407716
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 40 deletions.
1 change: 0 additions & 1 deletion macros/src/type/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ pub fn derive(input: proc_macro::TokenStream) -> syn::Result<proc_macro::TokenSt
#deprecated,
SID,
IMPL_LOCATION,
#should_export,
<Self as #crate_ref::Type>::inline(opts, generics)
)
}
Expand Down
8 changes: 0 additions & 8 deletions src/datatype/named.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ pub struct NamedDataTypeExt {
pub(crate) sid: SpectaID,
/// The code location where this type is implemented. Used for error reporting.
pub(crate) impl_location: ImplLocation,
// TODO: Undeprecate this and handle it properly!
// TODO: Support different export contexts
/// DEPRECATED. This is not used and shouldn't be. Will be removed in Specta v2!
pub(crate) export: Option<bool>,
}

impl NamedDataTypeExt {
Expand All @@ -23,10 +19,6 @@ impl NamedDataTypeExt {
pub fn impl_location(&self) -> &ImplLocation {
&self.impl_location
}

pub fn export(&self) -> Option<bool> {
self.export
}
}

/// A named type represents a non-primitive type capable of being exported as it's own named entity.
Expand Down
8 changes: 1 addition & 7 deletions src/export/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,10 @@ pub fn ts(path: &str) -> Result<(), ExportError> {
pub fn ts_with_cfg(path: &str, conf: &ExportConfig) -> Result<(), ExportError> {
let mut out = "// This file has been generated by Specta. DO NOT EDIT.\n\n".to_string();

let export_by_default = conf.export_by_default.unwrap_or(true);

// We sort by name to detect duplicate types BUT also to ensure the output is deterministic. The SID can change between builds so is not suitable for this.
let types = get_types()
.filter(|(_, v)| match v {
Some(v) => v
.ext()
.as_ref()
.and_then(|ext| ext.export)
.unwrap_or(export_by_default),
Some(_) => true,
None => {
unreachable!("Placeholder type should never be returned from the Specta functions!")
}
Expand Down
7 changes: 1 addition & 6 deletions src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,13 @@ pub mod construct {
deprecated: Option<DeprecatedType>,
sid: SpectaID,
impl_location: ImplLocation,
export: Option<bool>,
inner: DataType,
) -> NamedDataType {
NamedDataType {
name,
docs,
deprecated,
ext: Some(NamedDataTypeExt {
sid,
impl_location,
export,
}),
ext: Some(NamedDataTypeExt { sid, impl_location }),
inner,
}
}
Expand Down
17 changes: 0 additions & 17 deletions src/lang/ts/export_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ pub struct ExportConfig {
pub(crate) comment_exporter: Option<CommentFormatterFn>,
/// How the resulting file should be formatted.
pub(crate) formatter: Option<FormatterFn>,
/// Whether to export types by default.
/// This can be overridden on a type basis by using `#[specta(export)]`.
#[cfg(feature = "export")]
pub(crate) export_by_default: Option<bool>,
}

impl ExportConfig {
Expand Down Expand Up @@ -68,17 +64,6 @@ impl ExportConfig {
self
}

/// Configure whether or not to export types by default.
///
/// This can be overridden on a specific type by using `#[specta(export)]`.
///
/// This parameter only takes effect when this configuration if passed into [`export::ts_with_cfg`](crate::export::ts_with_cfg)
#[cfg(feature = "export")]
pub fn export_by_default(mut self, export: Option<bool>) -> Self {
self.export_by_default = export;
self
}

/// Run the specified formatter on the given path.
pub fn run_format(&self, path: PathBuf) -> io::Result<()> {
if let Some(formatter) = self.formatter {
Expand All @@ -94,8 +79,6 @@ impl Default for ExportConfig {
bigint: Default::default(),
comment_exporter: Some(comments::js_doc),
formatter: None,
#[cfg(feature = "export")]
export_by_default: None,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/type/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl<T> Type for std::marker::PhantomData<T> {
// Serde does no support `Infallible` as it can't be constructed so a `&self` method is uncallable on it.
#[allow(unused)]
#[derive(Type)]
#[specta(remote = std::convert::Infallible, crate = crate)]
#[specta(remote = std::convert::Infallible, crate = crate, export = false)]
pub enum Infallible {}

impl<T: Type> Type for std::ops::Range<T> {
Expand Down

0 comments on commit 5407716

Please sign in to comment.