@@ -36,6 +36,7 @@ use self::FormattedText::{Indent, Line, Branch, BlankLine};
36
36
pub struct CodeGenerationCommand {
37
37
output_directory : PathBuf ,
38
38
default_parent_module : Vec < String > ,
39
+ raw_code_generator_request_path : Option < PathBuf > ,
39
40
}
40
41
41
42
impl CodeGenerationCommand {
@@ -44,6 +45,7 @@ impl CodeGenerationCommand {
44
45
CodeGenerationCommand {
45
46
output_directory : PathBuf :: new ( ) ,
46
47
default_parent_module : Vec :: new ( ) ,
48
+ raw_code_generator_request_path : None ,
47
49
}
48
50
}
49
51
@@ -65,6 +67,14 @@ impl CodeGenerationCommand {
65
67
self
66
68
}
67
69
70
+ /// Sets the raw code generator request output path.
71
+ pub fn raw_code_generator_request_path < P > ( & mut self , path : P ) -> & mut Self
72
+ where P : AsRef < Path >
73
+ {
74
+ self . raw_code_generator_request_path = Some ( path. as_ref ( ) . to_path_buf ( ) ) ;
75
+ self
76
+ }
77
+
68
78
/// Generates Rust code according to a `schema_capnp::code_generator_request` read from `inp`.
69
79
pub fn run < T > ( & mut self , inp : T ) -> :: capnp:: Result < ( ) >
70
80
where T : std:: io:: Read
@@ -119,6 +129,12 @@ impl CodeGenerationCommand {
119
129
}
120
130
}
121
131
}
132
+
133
+ if let Some ( raw_code_generator_request) = & self . raw_code_generator_request_path {
134
+ let raw_code_generator_request_file = :: std:: fs:: File :: create ( & raw_code_generator_request) . map_err ( convert_io_err) ?;
135
+ serialize:: write_message_segments ( WriteWrapper { inner : raw_code_generator_request_file } , & message. into_segments ( ) ) ?;
136
+ }
137
+
122
138
Ok ( ( ) )
123
139
}
124
140
}
@@ -2065,6 +2081,19 @@ impl <R> capnp::io::Read for ReadWrapper<R> where R: std::io::Read {
2065
2081
}
2066
2082
}
2067
2083
2084
+ // The capnp crate defines a blanket impl of capnp::Write for R where R: std::io::Write,
2085
+ // but we can't use that here because it lives behind the "std" feature flag.
2086
+ struct WriteWrapper < W > where W : std:: io:: Write {
2087
+ inner : W ,
2088
+ }
2089
+
2090
+ impl < W > capnp:: io:: Write for WriteWrapper < W > where W : std:: io:: Write {
2091
+ fn write_all ( & mut self , buf : & [ u8 ] ) -> :: capnp:: Result < ( ) > {
2092
+ std:: io:: Write :: write_all ( & mut self . inner , buf) . map_err ( convert_io_err) ?;
2093
+ Ok ( ( ) )
2094
+ }
2095
+ }
2096
+
2068
2097
#[ deprecated( since = "0.14.2" , note = "Use CodeGenerationCommand::run() instead." ) ]
2069
2098
pub fn generate_code < T > ( inp : T , out_dir : & :: std:: path:: Path ) -> :: capnp:: Result < ( ) >
2070
2099
where T : :: std:: io:: Read
0 commit comments