Skip to content

Commit

Permalink
setup project file strcuture
Browse files Browse the repository at this point in the history
  • Loading branch information
zuowenjian committed Apr 22, 2018
1 parent e4290fe commit e9b945d
Show file tree
Hide file tree
Showing 20 changed files with 98 additions and 96 deletions.
4 changes: 2 additions & 2 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "core"
name = "rg_core"
version = "0.1.0"
authors = ["zuowenjian <[email protected]>"]


[lib]
name = "core"
name = "rg_core"
path = "src/lib.rs"

[dependencies]
Expand Down
4 changes: 2 additions & 2 deletions core/src/inner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub trait InnerContainer {

mod env ;
mod prj ;
mod rgm ;
pub mod rgm ;
mod sys ;
mod var ;
mod proxy ;
Expand Down Expand Up @@ -91,7 +91,7 @@ impl <T> InvokeStop for T where T: InnerContainer
}


trait Compose
pub trait Compose
{
fn build(&mut self,parser : &ParserBox,god :&ResFatory) ;
fn regist(&mut self, res : ResBox);
Expand Down
46 changes: 12 additions & 34 deletions core/src/inner/rgm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,44 +64,22 @@ mod tests
use parser::* ;
use std::cell::RefCell;
use pretty_env_logger ;
type RgDataVec = Vec<ParseResult> ;
struct StubParser
{
data : RefCell<RgDataVec> ,
}
impl StubParser
{
pub fn new() -> StubParser
{
let env = map!( "_name" => "dev" ) ;
let mut data = vec![
ParseResult::inn( RgvType::Env , map!( "_name" => "dev" )) ,
ParseResult::inn( RgvType::Vars , map!( "x" => "256" , "y" => "24")) ,
ParseResult::inn( res_of("Echo") , map!( "value" => "china")) ,
ParseResult::end() ,
ParseResult::inn( RgvType::System , map!( "_name" => "api" ) ) ,
ParseResult::inn( RgvType::Vars , map!( "x" => "256" , "y" => "24")) ,
ParseResult::end() ,
];
data.reverse();

StubParser{ data : RefCell::new(data)}
}
}
impl Parser for StubParser
{
fn next(&self) -> Option<ParseResult>
{
let mut data = self.data.borrow_mut() ;
data.pop()
}
}

#[test]
fn use_it()
{
pretty_env_logger::init();
let parser : ParserBox = Box::new(StubParser::new()) ;
let mut data = vec![
ParseResult::inn( RgvType::Env , map!( "_name" => "dev" )) ,
ParseResult::inn( RgvType::Vars , map!( "x" => "256" , "y" => "24")) ,
ParseResult::inn( res_of("Echo") , map!( "value" => "china")) ,
ParseResult::end() ,
ParseResult::inn( RgvType::System , map!( "_name" => "api" ) ) ,
ParseResult::inn( RgvType::Vars , map!( "x" => "256" , "y" => "24")) ,
ParseResult::end() ,
];


let parser : ParserBox = Box::new(StubParser::new(data)) ;
let mut god = ResFatory::new() ;
mod_regist(&mut god);
let mut context = Context::new();
Expand Down
89 changes: 34 additions & 55 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,66 +11,45 @@ extern crate lazy_static;

extern crate toml;

#[macro_export]
macro_rules! use_min_lib {
() => {

#[allow(unused_imports)]
use std ;
#[allow(unused_imports)]
use err ;
#[allow(unused_imports)]
use def::* ;
}
}

#[macro_export]
macro_rules! use_lib {
() => {

#[allow(unused_imports)]
use std ;
#[allow(unused_imports)]
use err ;
#[allow(unused_imports)]
use err::ResultFlow ;
#[allow(unused_imports)]
use def::* ;
#[allow(unused_imports)]
use model::* ;
}
}

#[macro_export]
macro_rules! use_test {
() => {

#[allow(unused_imports)]
use std ;
#[allow(unused_imports)]
use file;
#[allow(unused_imports)]
use err ;
#[allow(unused_imports)]
use def::* ;
#[allow(unused_imports)]
use model::* ;
}
}

#[macro_use]
mod err ;
pub mod err ;
#[macro_use]
mod def ;
pub mod def ;
pub mod model ;
pub mod creator ;
mod parser ;
pub mod parser ;
mod res ;
mod inner ;
pub mod inner ;


use err::* ;
use def::* ;
use model::* ;
use parser::* ;
use creator::* ;
use inner::rgm::* ;
use inner::*;

pub fn rg_main()
{
let mut data = vec![
ParseResult::inn( RgvType::Env , map!( "_name" => "dev" )) ,
ParseResult::inn( RgvType::Vars , map!( "x" => "256" , "y" => "24")) ,
ParseResult::inn( res_of("Echo") , map!( "value" => "china")) ,
ParseResult::end() ,
ParseResult::inn( RgvType::System , map!( "_name" => "api" ) ) ,
ParseResult::inn( RgvType::Vars , map!( "x" => "256" , "y" => "24")) ,
ParseResult::end() ,
];

let parser : ParserBox = Box::new(StubParser::new(data)) ;
let mut god = ResFatory::new() ;
mod_regist(&mut god);
let mut context = Context::new();
let mut main = RGMain::new() ;
main.build(&parser,&god) ;
debug!("main: {:?}", main) ;
main.conf(&mut context) ;


pub fn __main() {
assert!(false) ;
debug!("hello") ;
}

23 changes: 23 additions & 0 deletions core/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,26 @@ pub trait Parser
}
pub type ParserBox = Box<Parser> ;


use std::cell::RefCell ;
pub type RgDataVec = Vec<ParseResult> ;
pub struct StubParser
{
data : RefCell<RgDataVec> ,
}
impl StubParser
{
pub fn new( mut data : RgDataVec) -> StubParser
{
data.reverse();
StubParser{ data : RefCell::new(data)}
}
}
impl Parser for StubParser
{
fn next(&self) -> Option<ParseResult>
{
let mut data = self.data.borrow_mut() ;
data.pop()
}
}
2 changes: 1 addition & 1 deletion extends/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "extends"
name = "rg_exts"
version = "0.1.0"
authors = ["zuowenjian <[email protected]>"]

Expand Down
1 change: 1 addition & 0 deletions extends/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Empty file.
Empty file added extends/src/service/crontab.rs
Empty file.
3 changes: 3 additions & 0 deletions extends/src/service/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}
Empty file added extends/src/service/mysql.rs
Empty file.
Empty file added extends/src/service/nginx.rs
Empty file.
Empty file added extends/src/service/php_fpm.rs
Empty file.
Empty file added extends/src/service/varnishd.rs
Empty file.
Empty file added extends/src/unix/copy.rs
Empty file.
Empty file added extends/src/unix/link.rs
Empty file.
Empty file added extends/src/unix/mod.rs
Empty file.
Empty file added extends/src/unix/path.rs
Empty file.
10 changes: 9 additions & 1 deletion rg/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
[package]
name = "rg"
name = "rgger-nx"
version = "0.1.0"
authors = ["zuowenjian <[email protected]>"]

[dependencies]
log = "0.4.1"
pretty_env_logger = "0.2"
toml = "0.4"
rg_core = { path = "../core", version = "*" }
rg_exts = { path = "../extends", version = "*" }



12 changes: 11 additions & 1 deletion rg/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@

#[macro_use]
extern crate log;
extern crate pretty_env_logger;
#[macro_use]
extern crate rg_core ;


fn main() {
println!("Hello, world!");

pretty_env_logger::init();
rg_core::rg_main();
}

0 comments on commit e9b945d

Please sign in to comment.