Skip to content

Commit

Permalink
Rename TypeSID to SpectaID
Browse files Browse the repository at this point in the history
  • Loading branch information
oscartbeaumont committed Aug 31, 2023
1 parent f0b5d65 commit fe21c4c
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 16 deletions.
4 changes: 2 additions & 2 deletions macros/src/type/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub fn derive(input: proc_macro::TokenStream) -> syn::Result<proc_macro::TokenSt
Ok(quote! {
const _: () = {
// We do this so `sid!()` is only called once, preventing the type ended up with multiple ids
const SID: #crate_name::TypeSid = #crate_name::sid!(@with_specta_path; #name; #crate_name);
const SID: #crate_name::SpectaID = #crate_name::sid!(@with_specta_path; #name; #crate_name);
const IMPL_LOCATION: #crate_name::ImplLocation = #crate_name::impl_location!(@with_specta_path; #crate_name);

// We do this so `sid!()` is only called once, preventing the type ended up with multiple ids
Expand All @@ -139,7 +139,7 @@ pub fn derive(input: proc_macro::TokenStream) -> syn::Result<proc_macro::TokenSt

#[automatically_derived]
impl #bounds #crate_name::NamedType for #ident #type_args #where_bound {
const SID: #crate_name::TypeSid = SID;
const SID: #crate_name::SpectaID = SID;
const IMPL_LOCATION: #crate_name::ImplLocation = IMPL_LOCATION;

fn named_data_type(opts: #crate_name::DefOpts, generics: &[#crate_name::DataType]) -> std::result::Result<#crate_name::NamedDataType, #crate_name::ExportError> {
Expand Down
1 change: 1 addition & 0 deletions src/datatype/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::DataType;
#[derive(Debug, Clone, PartialEq)]
#[allow(non_camel_case_types)]
#[allow(missing_docs)]
#[non_exhaustive]
pub enum LiteralType {
i8(i8),
i16(i16),
Expand Down
6 changes: 3 additions & 3 deletions src/datatype/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ pub use r#enum::*;
pub use r#struct::*;
pub use tuple::*;

use crate::TypeSid;
use crate::SpectaID;

/// A map used to store the types "discovered" while exporting a type.
/// You can iterate over this to export all types which the type/s you exported references on.
///
/// [`None`] indicates that the entry is a placeholder. It was reference but we haven't reached it's definition yet.
pub type TypeMap = BTreeMap<TypeSid, Option<NamedDataType>>;
pub type TypeMap = BTreeMap<SpectaID, Option<NamedDataType>>;

/// Arguments for [`Type::inline`](crate::Type::inline), [`Type::reference`](crate::Type::reference) and [`Type::definition`](crate::Type::definition).
pub struct DefOpts<'a> {
Expand Down Expand Up @@ -73,7 +73,7 @@ pub enum DataType {
#[allow(missing_docs)]
pub struct DataTypeReference {
pub name: Cow<'static, str>,
pub sid: TypeSid,
pub sid: SpectaID,
pub generics: Vec<DataType>,
}

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

use crate::{DataType, EnumType, GenericType, ImplLocation, StructType, TupleType, TypeSid};
use crate::{DataType, EnumType, GenericType, ImplLocation, SpectaID, StructType, TupleType};

/// A NamedDataTypeImpl includes extra information which is only available for [NamedDataType]'s that come from a real Rust type.
#[derive(Debug, Clone, PartialEq)]
pub struct NamedDataTypeExt {
/// The Specta ID for the type. The value for this should come from the `sid!();` macro.
pub(crate) sid: TypeSid,
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!
Expand All @@ -16,7 +16,7 @@ pub struct NamedDataTypeExt {
}

impl NamedDataTypeExt {
pub fn sid(&self) -> &TypeSid {
pub fn sid(&self) -> &SpectaID {

Check warning on line 19 in src/datatype/named.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a method

warning: missing documentation for a method --> src/datatype/named.rs:19:5 | 19 | pub fn sid(&self) -> &SpectaID { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: the lint level is defined here --> src/lib.rs:58:58 | 58 | #![warn(clippy::all, clippy::unwrap_used, clippy::panic, missing_docs)] | ^^^^^^^^^^^^
&self.sid
}

Expand Down
2 changes: 1 addition & 1 deletion src/export/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct TypesIter {
}

impl Iterator for TypesIter {
type Item = (TypeSid, Option<NamedDataType>);
type Item = (SpectaID, Option<NamedDataType>);

fn next(&mut self) -> Option<Self::Item> {
let (k, v) = self.lock.0.iter().nth(self.index)?;
Expand Down
4 changes: 2 additions & 2 deletions src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub use specta_macros::fn_datatype;
pub mod construct {
use std::borrow::Cow;

use crate::{datatype::*, ImplLocation, TypeSid};
use crate::{datatype::*, ImplLocation, SpectaID};

pub const fn r#struct(
generics: Vec<GenericType>,
Expand All @@ -33,7 +33,7 @@ pub mod construct {
name: Cow<'static, str>,
comments: Vec<Cow<'static, str>>,
deprecated: Option<Cow<'static, str>>,
sid: TypeSid,
sid: SpectaID,
impl_location: ImplLocation,
export: Option<bool>,
item: NamedDataTypeItem,
Expand Down
2 changes: 1 addition & 1 deletion src/type/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ macro_rules! impl_containers {
}

impl<T: NamedType> NamedType for $container<T> {
const SID: TypeSid = T::SID;
const SID: SpectaID = T::SID;
const IMPL_LOCATION: ImplLocation = T::IMPL_LOCATION;

fn named_data_type(opts: DefOpts, generics: &[DataType]) -> Result<NamedDataType, ExportError> {
Expand Down
8 changes: 4 additions & 4 deletions src/type/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub trait Type {
/// NamedType represents a type that can be converted into [NamedDataType].
/// This will be all types created by the derive macro.
pub trait NamedType: Type {
const SID: TypeSid;
const SID: SpectaID;

Check warning on line 115 in src/type/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for an associated constant

warning: missing documentation for an associated constant --> src/type/mod.rs:115:5 | 115 | const SID: SpectaID; | ^^^^^^^^^^^^^^^^^^^
const IMPL_LOCATION: ImplLocation;

Check warning on line 116 in src/type/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for an associated constant

warning: missing documentation for an associated constant --> src/type/mod.rs:116:5 | 116 | const IMPL_LOCATION: ImplLocation; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

/// this is equivalent to [Type::inline] but returns a [NamedDataType] instead.
Expand Down Expand Up @@ -146,7 +146,7 @@ pub trait Flatten: Type {}
///
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[doc(hidden)]
pub struct TypeSid(u64);
pub struct SpectaID(u64);

/// Compute an SID hash for a given type.
/// This hash function comes from https://stackoverflow.com/a/71464396
Expand All @@ -157,7 +157,7 @@ pub const fn internal_sid_hash(
file: &'static str,
// This is required for a unique hash because all impls generated by a `macro_rules!` will have an identical `module_path` and `file` value.
type_name: &'static str,
) -> TypeSid {
) -> SpectaID {
let mut hash = 0xcbf29ce484222325;
let prime = 0x00000100000001B3;

Expand Down Expand Up @@ -186,7 +186,7 @@ pub const fn internal_sid_hash(
i += 1;
}

TypeSid(hash)
SpectaID(hash)
}

/// Compute an SID hash for a given type.
Expand Down

0 comments on commit fe21c4c

Please sign in to comment.