chore: rename some struct

This commit is contained in:
appflowy
2022-02-18 23:04:55 +08:00
parent 6593855f8f
commit dd832b7482
16 changed files with 115 additions and 125 deletions

View File

@ -28,7 +28,7 @@ impl CrateConfig {
.flowy_config
.proto_crates
.iter()
.map(|name| path_buf_with_component(&self.crate_path, vec![&name]))
.map(|name| path_buf_with_component(&self.crate_path, vec![name]))
.collect::<Vec<PathBuf>>();
proto_paths
}

View File

@ -31,7 +31,7 @@ pub fn parse_crate_protobuf(crate_paths: Vec<String>) -> Vec<ProtobufCrateContex
.collect::<Vec<ProtobufCrateContext>>()
}
fn parse_files_protobuf(proto_crate_path: &PathBuf, proto_output_dir: &PathBuf) -> Vec<ProtoFile> {
fn parse_files_protobuf(proto_crate_path: &Path, proto_output_dir: &Path) -> Vec<ProtoFile> {
let mut gen_proto_vec: Vec<ProtoFile> = vec![];
// file_stem https://doc.rust-lang.org/std/path/struct.Path.html#method.file_stem
for (path, file_name) in WalkDir::new(proto_crate_path)
@ -54,7 +54,7 @@ fn parse_files_protobuf(proto_crate_path: &PathBuf, proto_output_dir: &PathBuf)
.unwrap_or_else(|_| panic!("Unable to parse file at {}", path));
let structs = get_ast_structs(&ast);
let proto_file = format!("{}.proto", &file_name);
let proto_file_path = path_string_with_component(&proto_output_dir, vec![&proto_file]);
let proto_file_path = path_string_with_component(proto_output_dir, vec![&proto_file]);
let mut proto_file_content = parse_or_init_proto_file(proto_file_path.as_ref());
structs.iter().for_each(|s| {

View File

@ -12,7 +12,7 @@ pub use proto_gen::*;
pub use proto_info::*;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::process::Command;
use walkdir::WalkDir;
@ -56,7 +56,7 @@ pub fn gen(crate_name: &str, proto_file_dir: &str) {
generate_rust_protobuf_files(&protoc_bin_path, &proto_file_paths, proto_file_dir);
}
fn generate_rust_protobuf_files(protoc_bin_path: &PathBuf, proto_file_paths: &Vec<String>, proto_file_dir: &str) {
fn generate_rust_protobuf_files(protoc_bin_path: &Path, proto_file_paths: &[String], proto_file_dir: &str) {
protoc_rust::Codegen::new()
.out_dir("./src/protobuf/model")
.protoc_path(protoc_bin_path)

View File

@ -94,18 +94,18 @@ pub fn is_hidden(entry: &walkdir::DirEntry) -> bool {
entry.file_name().to_str().map(|s| s.starts_with('.')).unwrap_or(false)
}
pub fn create_dir_if_not_exist(dir: &PathBuf) {
if !dir.as_path().exists() {
pub fn create_dir_if_not_exist(dir: &Path) {
if !dir.exists() {
std::fs::create_dir_all(dir).unwrap();
}
}
pub fn path_string_with_component(path: &PathBuf, components: Vec<&str>) -> String {
pub fn path_string_with_component(path: &Path, components: Vec<&str>) -> String {
path_buf_with_component(path, components).to_str().unwrap().to_string()
}
pub fn path_buf_with_component(path: &PathBuf, components: Vec<&str>) -> PathBuf {
let mut path_buf = path.clone();
pub fn path_buf_with_component(path: &Path, components: Vec<&str>) -> PathBuf {
let mut path_buf = path.to_path_buf();
for component in components {
path_buf.push(component);
}