File tree 3 files changed +32
-5
lines changed
3 files changed +32
-5
lines changed Original file line number Diff line number Diff line change 1
1
[package ]
2
2
name = " scip"
3
- version = " 0.1.0 "
3
+ version = " 0.1.1 "
4
4
edition = " 2021"
5
5
license = " Apache-2.0"
6
6
description = """
Original file line number Diff line number Diff line change 3
3
// This will pull generated code into `scip::types`
4
4
#[ path = "generated/mod.rs" ]
5
5
mod scip_mod;
6
-
7
6
pub use scip_mod:: scip as types;
8
7
9
8
// Exports symbol usage under scip::symbol namespace
10
9
pub mod symbol;
10
+
11
+ /// Write a message to a particular filepath.
12
+ ///
13
+ /// This allows users of the SCIP library to not add protobuf as
14
+ /// a direct dependency of the project (which can be useful to limit
15
+ /// usage of protobuf elsewhere if not desired).
16
+ pub fn write_message_to_file < P > (
17
+ path : P ,
18
+ msg : impl protobuf:: Message ,
19
+ ) -> Result < ( ) , Box < dyn std:: error:: Error > >
20
+ where
21
+ P : AsRef < std:: path:: Path > ,
22
+ {
23
+ use std:: io:: Write ;
24
+
25
+ let res = msg. write_to_bytes ( ) ?;
26
+ let output = std:: fs:: File :: create ( path) ?;
27
+ let mut writer = std:: io:: BufWriter :: new ( output) ;
28
+ writer. write_all ( & res) ?;
29
+
30
+ Ok ( ( ) )
31
+ }
Original file line number Diff line number Diff line change @@ -105,6 +105,12 @@ pub fn format_symbol(symbol: Symbol) -> String {
105
105
format_symbol_with ( symbol, SymbolFormatOptions :: default ( ) )
106
106
}
107
107
108
+ impl Symbol {
109
+ pub fn new_local ( id : usize ) -> Self {
110
+ internal_local_symbol ( id. to_string ( ) . as_str ( ) )
111
+ }
112
+ }
113
+
108
114
pub fn parse_symbol ( symbol : & str ) -> Result < Symbol , SymbolError > {
109
115
fn dot ( s : String ) -> String {
110
116
if s. as_str ( ) == "." {
@@ -118,7 +124,7 @@ pub fn parse_symbol(symbol: &str) -> Result<Symbol, SymbolError> {
118
124
119
125
let scheme = parser. accept_space_escaped_identifier ( "scheme" ) ?;
120
126
if scheme == "local" {
121
- return Ok ( new_local_symbol (
127
+ return Ok ( internal_local_symbol (
122
128
symbol
123
129
. chars ( )
124
130
. skip ( parser. index )
@@ -338,7 +344,7 @@ impl SymbolParser {
338
344
}
339
345
}
340
346
341
- fn new_local_symbol ( id : & str ) -> Symbol {
347
+ fn internal_local_symbol ( id : & str ) -> Symbol {
342
348
let descriptor = Descriptor {
343
349
name : id. to_string ( ) ,
344
350
disambiguator : "" . to_string ( ) ,
@@ -376,7 +382,7 @@ mod test {
376
382
fn parses_local ( ) {
377
383
assert_eq ! (
378
384
parse_symbol( "local a" ) . expect( "to parse local" ) ,
379
- new_local_symbol ( "a" )
385
+ internal_local_symbol ( "a" )
380
386
) ;
381
387
}
382
388
You can’t perform that action at this time.
0 commit comments