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 with_raw(self, raw: impl Into<Cow<'static, str>>) -> Self {
53 Self(self.0.with_raw(raw))
54 }
55
56 pub fn branded_type_impl(
60 self,
61 builder: impl for<'a> Fn(BrandedTypeExporter<'a>, &Branded) -> Result<Cow<'static, str>, Error>
62 + Send
63 + Sync
64 + 'static,
65 ) -> Self {
66 Self(self.0.branded_type_impl(builder))
67 }
68
69 pub fn export(&self, types: &Types, format: impl Format) -> Result<String, Error> {
73 self.0.export(types, format)
74 }
75
76 pub fn export_to(
82 &self,
83 path: impl AsRef<Path>,
84 types: &Types,
85 format: impl Format,
86 ) -> Result<(), Error> {
87 self.0.export_to(path, types, format)
88 }
89}
90
91impl AsRef<Exporter> for JSDoc {
92 fn as_ref(&self) -> &Exporter {
93 &self.0
94 }
95}
96
97impl AsMut<Exporter> for JSDoc {
98 fn as_mut(&mut self) -> &mut Exporter {
99 &mut self.0
100 }
101}