1 use protobuf::descriptor::FileDescriptorProto; 2 3 use crate::pure::convert::populate_dependencies; 4 use crate::pure::model; 5 use crate::pure::parser::ParserErrorWithLocation; 6 7 /// Parse imports from a `.proto` file. 8 /// 9 /// The result is [`FileDescriptorProto`] object with only `*dependency` fields filled. parse_dependencies(content: &str) -> Result<FileDescriptorProto, ParserErrorWithLocation>10pub fn parse_dependencies(content: &str) -> Result<FileDescriptorProto, ParserErrorWithLocation> { 11 let input = model::FileDescriptor::parse(content)?; 12 let mut output = FileDescriptorProto::new(); 13 populate_dependencies(&input, &mut output); 14 Ok(output) 15 } 16 17 #[cfg(test)] 18 mod test { 19 #[test] parse_dependencies()20 fn parse_dependencies() { 21 let deps = crate::pure::parse_dependencies::parse_dependencies( 22 r" 23 syntax = 'proto3'; 24 25 import 'google/protobuf/field_mask.proto'; 26 import public 'google/protobuf/struct.proto'; 27 28 message IgnoreMe {} 29 ", 30 ) 31 .unwrap(); 32 assert_eq!( 33 &[ 34 "google/protobuf/field_mask.proto", 35 "google/protobuf/struct.proto", 36 ], 37 &deps.dependency[..] 38 ); 39 assert_eq!(&[1], &deps.public_dependency[..]); 40 } 41 } 42