specta_typescript/
jsdoc.rs1use std::{borrow::Cow, path::Path};
2
3use specta::{Format, Types};
4
5use crate::{Branded, BrandedTypeExporter, Error, Exporter, Layout};
6
7#[derive(Debug, Clone)]
9#[non_exhaustive]
10pub struct JSDoc(Exporter);
11
12impl Default for JSDoc {
13 fn default() -> Self {
14 let mut exporter = Exporter::default();
15 exporter.jsdoc = true;
16 exporter.into()
17 }
18}
19
20impl From<JSDoc> for Exporter {
21 fn from(value: JSDoc) -> Self {
22 value.0
23 }
24}
25
26impl From<Exporter> for JSDoc {
27 fn from(mut value: Exporter) -> Self {
28 value.jsdoc = true;
29 Self(value)
30 }
31}
32
33impl JSDoc {
34 pub fn new() -> Self {
36 Default::default()
37 }
38
39 pub fn header(self, header: impl Into<Cow<'static, str>>) -> Self {
43 Self(self.0.header(header))
44 }
45
46 pub fn layout(self, layout: Layout) -> Self {
48 Self(self.0.layout(layout))
49 }
50
51 pub fn branded_type_impl(
55 self,
56 builder: impl for<'a> Fn(BrandedTypeExporter<'a>, &Branded) -> Result<Cow<'static, str>, Error>
57 + Send
58 + Sync
59 + 'static,
60 ) -> Self {
61 Self(self.0.branded_type_impl(builder))
62 }
63
64 pub fn export(&self, types: &Types, format: impl Format) -> Result<String, Error> {
68 self.0.export(types, format)
69 }
70
71 pub fn export_to(
77 &self,
78 path: impl AsRef<Path>,
79 types: &Types,
80 format: impl Format,
81 ) -> Result<(), Error> {
82 self.0.export_to(path, types, format)
83 }
84}
85
86impl AsRef<Exporter> for JSDoc {
87 fn as_ref(&self) -> &Exporter {
88 &self.0
89 }
90}
91
92impl AsMut<Exporter> for JSDoc {
93 fn as_mut(&mut self) -> &mut Exporter {
94 &mut self.0
95 }
96}