Skip to content

Commit

Permalink
Rename SpectaFunction* -> Function + fix docs from bad Tokio release
Browse files Browse the repository at this point in the history
  • Loading branch information
oscartbeaumont committed Apr 2, 2024
1 parent f75a1b7 commit bbbd1c3
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 48 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/docs.yml
Expand Up @@ -10,7 +10,7 @@ permissions:
statuses: write

env:
RUSTDOCFLAGS: --cfg docsrs
RUSTDOCFLAGS: --cfg docsrs2

jobs:
deploy-docs:
Expand All @@ -30,25 +30,25 @@ jobs:
state: "pending",
});
console.log(data); // TODO
- name: Checkout
uses: actions/checkout@v4

- name: Install system dependencies
run: sudo apt-get install librust-atk-dev libwebkit2gtk-4.0-dev build-essential libssl-dev libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev

- name: Install Node.js
uses: actions/setup-node@v4

- name: Install Rust
run: curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain nightly && source "$HOME/.cargo/env"

- name: Rust cache
uses: Swatinem/rust-cache@v2

- name: Build docs
run: cargo +nightly doc --all-features --no-deps

- name: Add index redirect
run: echo "<meta http-equiv=\"refresh\" content=\"0; url=specta\">" > target/doc/index.html

Expand All @@ -59,7 +59,7 @@ jobs:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}

- name: Update status check
uses: actions/github-script@v7
env:
Expand Down
7 changes: 2 additions & 5 deletions Cargo.toml
Expand Up @@ -12,10 +12,10 @@ keywords = ["async", "specta", "rspc", "typescript", "typesafe"]
categories = ["web-programming", "asynchronous"]
autotests = false

# /bin/sh RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --all-features
# /bin/sh RUSTDOCFLAGS="--cfg docsrs2" cargo +nightly doc --all-features
[package.metadata."docs.rs"]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
rustdoc-args = ["--cfg", "docsrs2"] # TODO: Rename to `docsrs2` once Tokio fixes https://github.com/tokio-rs/tokio/pull/6360

[[test]]
name = "integration_tests"
Expand Down Expand Up @@ -63,9 +63,6 @@ serde_yaml = ["dep:serde_yaml"]
## Support for [toml](https://github.com/toml-rs/toml)
toml = ["dep:toml"]

## Support for [Tauri](https://tauri.app). This is required when using [`specta::function`](macro@crate::specta) with Tauri Commands.
tauri = ["dep:tauri"]

#! External types
## [uuid](https://docs.rs/uuid) crate
uuid = ["dep:uuid"]
Expand Down
4 changes: 2 additions & 2 deletions src/export/mod.rs
@@ -1,9 +1,9 @@
mod export;
#[cfg(feature = "typescript")]
#[cfg_attr(docsrs, doc(cfg(feature = "typescript")))]
#[cfg_attr(docsrs2, doc(cfg(feature = "typescript")))]
mod ts;

pub use export::*;
#[cfg(feature = "typescript")]
#[cfg_attr(docsrs, doc(cfg(feature = "typescript")))]
#[cfg_attr(docsrs2, doc(cfg(feature = "typescript")))]
pub use ts::*;
14 changes: 6 additions & 8 deletions src/functions/arg.rs
Expand Up @@ -3,7 +3,7 @@ mod private {

/// Implemented by types that can be used as an argument in a function annotated with
/// [`specta`](crate::specta).
pub trait SpectaFunctionArg<TMarker> {
pub trait FunctionArg<TMarker> {
/// Gets the type of an argument as a [`DataType`].
///
/// Some argument types should be ignored (eg Tauri command State),
Expand All @@ -13,7 +13,7 @@ mod private {

pub enum FunctionArgMarker {}

impl<T: Type> SpectaFunctionArg<FunctionArgMarker> for T {
impl<T: Type> FunctionArg<FunctionArgMarker> for T {
fn to_datatype(type_map: &mut TypeMap) -> Option<DataType> {
Some(T::reference(type_map, &[]).inner)
}
Expand All @@ -23,26 +23,24 @@ mod private {
const _: () = {
pub enum FunctionArgTauriMarker {}

impl<R: tauri::Runtime> SpectaFunctionArg<FunctionArgTauriMarker> for tauri::Window<R> {
impl<R: tauri::Runtime> FunctionArg<FunctionArgTauriMarker> for tauri::Window<R> {
fn to_datatype(_: &mut TypeMap) -> Option<DataType> {
None
}
}

impl<'r, T: Send + Sync + 'static> SpectaFunctionArg<FunctionArgTauriMarker>
for tauri::State<'r, T>
{
impl<'r, T: Send + Sync + 'static> FunctionArg<FunctionArgTauriMarker> for tauri::State<'r, T> {
fn to_datatype(_: &mut TypeMap) -> Option<DataType> {
None
}
}

impl<R: tauri::Runtime> SpectaFunctionArg<FunctionArgTauriMarker> for tauri::AppHandle<R> {
impl<R: tauri::Runtime> FunctionArg<FunctionArgTauriMarker> for tauri::AppHandle<R> {
fn to_datatype(_: &mut TypeMap) -> Option<DataType> {
None
}
}
};
}

pub(crate) use private::SpectaFunctionArg;
pub(crate) use private::FunctionArg;
10 changes: 5 additions & 5 deletions src/functions/mod.rs
Expand Up @@ -62,7 +62,7 @@ pub struct FunctionDataType {
}

/// Implemented by functions that can be annoatated with [`specta`](crate::specta).
pub trait SpectaFunction<TMarker> {
pub trait Function<TMarker> {
/// Gets the type of a function as a [`FunctionDataType`].
fn to_datatype(
asyncness: bool,
Expand All @@ -75,7 +75,7 @@ pub trait SpectaFunction<TMarker> {
) -> FunctionDataType;
}

impl<TResultMarker, TResult: SpectaFunctionResult<TResultMarker>> SpectaFunction<TResultMarker>
impl<TResultMarker, TResult: FunctionResult<TResultMarker>> Function<TResultMarker>
for fn() -> TResult
{
fn to_datatype(
Expand Down Expand Up @@ -103,10 +103,10 @@ macro_rules! impl_typed_command {
paste::paste! {
impl<
TResultMarker,
TResult: SpectaFunctionResult<TResultMarker>,
TResult: FunctionResult<TResultMarker>,
$([<$i Marker>]),*,
$($i: SpectaFunctionArg<[<$i Marker>]>),*
> SpectaFunction<(TResultMarker, $([<$i Marker>]),*)> for fn($($i),*) -> TResult {
$($i: FunctionArg<[<$i Marker>]>),*
> Function<(TResultMarker, $([<$i Marker>]),*)> for fn($($i),*) -> TResult {
fn to_datatype(
asyncness: bool,
name: Cow<'static, str>,
Expand Down
12 changes: 6 additions & 6 deletions src/functions/result.rs
Expand Up @@ -5,20 +5,20 @@ mod private {

/// Implemented by types that can be returned from a function annotated with
/// [`specta`](crate::specta).
pub trait SpectaFunctionResult<TMarker> {
pub trait FunctionResult<TMarker> {
/// Gets the type of the result as a [`DataType`].
fn to_datatype(type_map: &mut TypeMap) -> DataType;
}

pub enum SpectaFunctionResultMarker {}
impl<T: Type> SpectaFunctionResult<SpectaFunctionResultMarker> for T {
pub enum FunctionResultMarker {}
impl<T: Type> FunctionResult<FunctionResultMarker> for T {
fn to_datatype(type_map: &mut TypeMap) -> DataType {
T::reference(type_map, &[]).inner
}
}

pub enum SpectaFunctionResultFutureMarker {}
impl<F> SpectaFunctionResult<SpectaFunctionResultFutureMarker> for F
pub enum FunctionResultFutureMarker {}
impl<F> FunctionResult<FunctionResultFutureMarker> for F
where
F: Future,
F::Output: Type,
Expand All @@ -29,4 +29,4 @@ mod private {
}
}

pub(crate) use private::SpectaFunctionResult;
pub(crate) use private::FunctionResult;
4 changes: 2 additions & 2 deletions src/internal.rs
Expand Up @@ -221,12 +221,12 @@ pub fn flatten<T: Type>(sid: SpectaID, type_map: &mut TypeMap, generics: &[DataT
#[cfg(feature = "functions")]
mod functions {
use super::*;
use crate::functions::{FunctionDataType, SpectaFunction};
use crate::functions::{Function, FunctionDataType};

#[doc(hidden)]
/// A helper for exporting a command to a [`CommandDataType`].
/// You shouldn't use this directly and instead should use [`fn_datatype!`](crate::fn_datatype).
pub fn get_fn_datatype<TMarker, T: SpectaFunction<TMarker>>(
pub fn get_fn_datatype<TMarker, T: Function<TMarker>>(
_: T,
asyncness: bool,
name: Cow<'static, str>,
Expand Down
14 changes: 7 additions & 7 deletions src/lang/mod.rs
@@ -1,11 +1,11 @@
// /// Alpha: [OpenAPI](https://www.openapis.org) language exporter.
// #[cfg(feature = "openapi")]
// #[cfg_attr(docsrs, doc(cfg(feature = "openapi")))]
// #[cfg_attr(docsrs2, doc(cfg(feature = "openapi")))]
// pub mod openapi;

/// [TypeScript](https://www.typescriptlang.org) language exporter.
#[cfg(feature = "typescript")]
#[cfg_attr(docsrs, doc(cfg(feature = "typescript")))]
#[cfg_attr(docsrs2, doc(cfg(feature = "typescript")))]
pub mod ts;

#[cfg(all(feature = "js_doc", not(feature = "typescript")))]
Expand All @@ -15,29 +15,29 @@ compile_error!("`js_doc` feature requires `typescript` feature to be enabled");
///
/// Also requires `typescript` feature to be enabled.
#[cfg(all(feature = "js_doc", feature = "typescript"))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "js_doc", feature = "typescript"))))]
#[cfg_attr(docsrs2, doc(cfg(all(feature = "js_doc", feature = "typescript"))))]
pub mod js_doc {
pub use super::ts::js_doc::*;
}

// /// [Rust](https://www.rust-lang.org) language exporter.
// #[cfg(feature = "rust")]
// #[cfg_attr(docsrs, doc(cfg(feature = "rust")))]
// #[cfg_attr(docsrs2, doc(cfg(feature = "rust")))]
// pub mod rust;

// /// [Swift](https://www.swift.org) language exporter.
// #[cfg(feature = "swift")]
// #[cfg_attr(docsrs, doc(cfg(feature = "swift")))]
// #[cfg_attr(docsrs2, doc(cfg(feature = "swift")))]
// pub mod swift;

// /// [Kotlin](https://kotlinlang.org) language exporter.
// #[cfg(feature = "kotlin")]
// #[cfg_attr(docsrs, doc(cfg(feature = "kotlin")))]
// #[cfg_attr(docsrs2, doc(cfg(feature = "kotlin")))]
// pub mod kotlin;

// /// [Go Lang](https://go.dev) language exporter.
// #[cfg(feature = "go")]
// #[cfg_attr(docsrs, doc(cfg(feature = "go")))]
// #[cfg_attr(docsrs2, doc(cfg(feature = "go")))]
// pub mod go;

macro_rules! primitive_def {
Expand Down
2 changes: 1 addition & 1 deletion src/lang/ts/mod.rs
Expand Up @@ -96,7 +96,7 @@ pub fn export_named_datatype(
///
/// Eg. `function name();`
#[cfg(feature = "functions")]
#[cfg_attr(docsrs, doc(cfg(feature = "functions")))]
#[cfg_attr(docsrs2, doc(cfg(feature = "functions")))]
pub fn export_function_header(
dt: crate::functions::FunctionDataType,
config: &ExportConfig,
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Expand Up @@ -2,7 +2,7 @@
#![forbid(unsafe_code)]
#![warn(clippy::all, clippy::unwrap_used, clippy::panic)] // TODO: missing_docs
#![allow(clippy::module_inception)]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(docsrs2, feature(doc_cfg))]
#![doc(
html_logo_url = "https://github.com/oscartbeaumont/specta/raw/main/.github/logo-128.png",
html_favicon_url = "https://github.com/oscartbeaumont/specta/raw/main/.github/logo-128.png"
Expand All @@ -15,11 +15,11 @@ pub mod internal;
pub mod datatype;
/// Provides the global type store and a method to export them to other languages.
#[cfg(feature = "export")]
#[cfg_attr(docsrs, doc(cfg(feature = "export")))]
#[cfg_attr(docsrs2, doc(cfg(feature = "export")))]
pub mod export;
/// Support for exporting Rust functions.
#[cfg(feature = "functions")]
#[cfg_attr(docsrs, doc(cfg(feature = "functions")))]
#[cfg_attr(docsrs2, doc(cfg(feature = "functions")))]
pub mod functions;
mod lang;
mod selection;
Expand Down Expand Up @@ -137,7 +137,7 @@ pub use specta_macros::DataTypeFrom;
/// }
/// ```
#[cfg(feature = "functions")]
#[cfg_attr(docsrs, doc(cfg(feature = "functions")))]
#[cfg_attr(docsrs2, doc(cfg(feature = "functions")))]
pub use specta_macros::specta;

#[cfg(doctest)]
Expand Down
2 changes: 1 addition & 1 deletion src/selection.rs
Expand Up @@ -33,7 +33,7 @@
/// ```
// TODO: better docs w/ example
#[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
#[cfg_attr(docsrs2, doc(cfg(feature = "serde")))]
#[macro_export]
macro_rules! selection {
( $s:expr, { $($n:ident),+ $(,)? } ) => {{
Expand Down

0 comments on commit bbbd1c3

Please sign in to comment.