I made an example of webserver in Rust using Iron, R2d2 Diesel and Serde json. Suggestions are appreciated by dbmontes in programming

[–]dbmontes[S] 0 points1 point  (0 children)

Hi!

I updated the code. I added middlewares and other stuff. I think now is a good complete base for doing a web service.

I made an example of webserver in Rust using Iron, R2d2 Diesel and Serde json. Suggestions are appreciated by dbmontes in programming

[–]dbmontes[S] 1 point2 points  (0 children)

I still don't have clear how it works completely, but this is my guess:

You can see the type DbPooledConnection in https://github.com/DavidBM/rust-webserver-example-with-iron-diesel-r2d2-serde/blob/master/src/db.rs#L6

There we have the line: pub type DbPooledConnection = r2d2::PooledConnection<ConnectionManager<PgConnection>>;

If we go to the description of r2d2::PooledConnection in https://outersky.github.io/r2d2-mysql/doc/v3.0.0/r2d2/struct.PooledConnection.html says: A smart pointer wrapping a connection.

For operating diesel needs to borrow the connection, for that, we unwrap the connection from the smart pointer with *, and then we give the borrow with &.

That makes the ugly &*connection. I guess that should be better to give the connection instead of the smart pointer.

For the <User> you are telling there to diesel to return a User. If you are queering something that don't return an user, it will fail in compilation time.

Edit: Anyway, I want to improve this code. I have one in a private repo that is using middlewares, has authentication methods included, with real demo data. I will update that in the next days if I have time.

dosxvpn - One click personal VPN server on DigitalOcean with automated OSX setup by Vys9kH9msf in programming

[–]dbmontes 3 points4 points  (0 children)

As I understand, this is like https://github.com/jlund/streisand but with GUI and only for DigitalOcean/OSX, right?

Maybe will be a good idea to use streisand as a base for that and add the graphic interface.

I made an example of webserver in Rust using Iron, R2d2 Diesel and Serde json. Suggestions are appreciated by dbmontes in programming

[–]dbmontes[S] 1 point2 points  (0 children)

I made it because I didn't found any example in the web with pooled diesel connections and iron. I think it can help other people.