Giter Site home page Giter Site logo

actixweb's Introduction

actixweb

$ cargo run

actixweb's People

Contributors

abrcdf1023 avatar

Stargazers

Roman avatar

Watchers

James Cloos avatar  avatar

actixweb's Issues

鐵人賽討論

嗨你好,不知道你還沒有在繼續寫rust呢

我最近也在學rust,剛好看到了你的文章,幫助很多,感謝你的分享。

這裡想要跟你分享一些地方,主要在最後介紹rust crate的部份。

其實 rust 的 crate、module系統我看著 the rust book 困惑了好一陣子才弄懂問題在哪。

我發現你的文章跟實作也都沒有特別提到,所以在這裡提一下(ithome的帳號還在新手村,不想解任務所以不能回文),

也許你可以加進文章的說明中,不然我發現常常寫rust的人會把它當 先備知識,然後新手可能會有點困惑。

以下幾點:

  • rust 的 root 有兩個,if rust as lib,root is lib.rs、if rust as bin,root is main.rs;if a crate has more than one bin,can put file in bin folder。這裡文章都有提到。
  • 如果要將rust code 分在不同的檔案中,一個rs檔會是一個 rust module。
  • 所有的rust module,都必須要從 root define module(mod ),才有辦法使用use引入。因此rust 的 path 跟檔案系統的path很像,但是不一樣。
  • rust 的資料夾結構有約定。在root 中(i.e. lib.rs or main.rs)使用 mod <module> ,會從資料夾底下找同名的 .rs檔;如 mod model 會尋找 src/model.rs
  • 如果上面 src/.rs 沒有找到的話,會再去找同名資料夾底下的 mod.rs檔。如上述的 mod model ,如果找不到.rs檔,會再去找src/model/mod.rs.
  • 如果再 model.rs ( or src/model/mod.rs)內,再define 其它 module 的話,就會使用上述的規定,找相對資料夾底下(src/model)底下的檔案(.rs)。
  • 以 此範例的 source code來說,在lib.rs中,有difine module
// ....
pub mod schema;
pub mod models;
// ...

然後,在 main.rs 中有import extern crate

// actixweb 就是這個範例 package的 name
extern crate actixweb;

因此才可以在 main.rs中使用所謂的 “相對路徑”

use self::actixweb::*;
use self::models::{Chinese, NewPost, UpdatePost};

另外,我想這樣子設計有可能不是所謂的 rust idiomatic。既然此app是做為 bin,而且也沒有共享問題,那 root crate 應該就只有一個,也就是 main.rs。

更正,搜尋一下以後,發現即使是 bin,同時有 lib.rs 跟 main.rs才是推薦的模式。

/mod.rs 在rust book 沒有,但是在 rust lang裡面有提到。所以我想可能也不是 rist idomatic的寫法。最推薦的寫法,應該是 rust book中寫的份檔案方式。

以上跟你分享討論。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.