Skip to content

Commit 244cea9

Browse files
committed
Use TypeId internally
1 parent 59deef9 commit 244cea9

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

packages/cw-schema/src/lib.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -145,23 +145,14 @@ pub enum Schema {
145145
}
146146

147147
#[derive(Hash, PartialEq, Eq)]
148-
pub struct Identifier(&'static str);
148+
pub struct Identifier(core::any::TypeId);
149149

150150
impl Identifier {
151151
pub fn of<T>() -> Self
152152
where
153-
T: ?Sized,
153+
T: ?Sized + 'static,
154154
{
155-
Self(core::any::type_name::<T>())
156-
}
157-
}
158-
159-
impl Serialize for Identifier {
160-
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
161-
where
162-
S: serde::Serializer,
163-
{
164-
self.0.serialize(serializer)
155+
Self(core::any::TypeId::of::<T>())
165156
}
166157
}
167158

@@ -191,7 +182,7 @@ impl SchemaVisitor {
191182
}
192183
}
193184

194-
pub trait Schemaifier {
185+
pub trait Schemaifier: 'static {
195186
#[doc(hidden)]
196187
fn id() -> Identifier {
197188
Identifier::of::<Self>()

packages/cw-schema/tests/snapshots/basic__snapshot_jsonschema.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,18 @@ expression: schema
392392
"type",
393393
"inner"
394394
]
395+
},
396+
{
397+
"type": "object",
398+
"properties": {
399+
"type": {
400+
"type": "string",
401+
"const": "unit"
402+
}
403+
},
404+
"required": [
405+
"type"
406+
]
395407
}
396408
],
397409
"required": [

0 commit comments

Comments
 (0)