These are chat archives for rust-lang/rust

2nd
Jun 2018
Otavio Salvador
@otavio
Jun 02 2018 00:04
Is there someone willing to review a small crate, from a new Rust user? I'd to get review in code, docs and any other possible improvement: https://crates.io/crates/easy_process
tandrysyawaludin
@tandrysyawaludin
Jun 02 2018 04:09
Hi, any one know how to make this code simplier? can i just use one .mount
.mount(
      "/categories_of_trash",
      routes![category_of_trash_module::read_all_categories],
    )
    .mount(
      "/transactions",
      routes![transaction_module::read_all_transactions],
    )
    .mount("/suppliers", routes![supplier_module::read_all_suppliers])
Robot Chu
@Turing-Chu
Jun 02 2018 06:02
what does the mean of ‘a ?
struct Parser<'a> {
@Turing-Chu
Robot Chu
@Turing-Chu
Jun 02 2018 06:16
ok , thks
Dylan DPC
@Dylan-DPC
Jun 02 2018 06:31
@otavio nice. but what's the gain of using your crate over firing a normal command using std::process::Command?
Fredrik Portström
@portstrom
Jun 02 2018 09:41
@otavio It seems like almost all of the code is about providing a wrapper that UTF-8 decodes the output. This isn't even mentioned in the description of the crate. It would be better to return the original output without wrapping it, so it can be used as binary data.
tandrysyawaludin
@tandrysyawaludin
Jun 02 2018 15:19
is there alternative of .is_ok()?because i always get true although with wrong primary key
Dylan DPC
@Dylan-DPC
Jun 02 2018 15:23
@tandrysyawaludin for what? can you give us an example :)
tandrysyawaludin
@tandrysyawaludin
Jun 02 2018 15:24
pub fn update(id: i32, partner: AlreadyPartner, connection: &PgConnection) -> bool {
    diesel::update(partners::table.find(id))
      .set(&partner)
      .execute(connection)
      .is_ok()
  }
although i give the id is wrong, the result still true
@Dylan-DPC
Dylan DPC
@Dylan-DPC
Jun 02 2018 15:28
haven't worked with diesel so sorry :)
tandrysyawaludin
@tandrysyawaludin
Jun 02 2018 16:17
anyone know how to check existing data?
Bryan Burgers
@bryanburgers
Jun 02 2018 18:35
Can you print out the result of execute? See what it contains?
ozgurakkurt
@ozgurakkurt
Jun 02 2018 21:43

Hi, I am trying to make a rest api with hyper like this:

fn router(req: Request<Body>) -> Return {
    match (req.method(), req.uri().path()) {
        (&Method::POST, "/api/signup") => signup(req),
        (&Method::GET, _) => index(),
        _ => not_found(),
    }
}

But I get this error:

error[E0507]: cannot move out of borrowed content
--> src\main.rs:25:15
|
25 | let fut = req.body()
| ^^^^^^^^^^ cannot move out of borrowed content

How can I read the uri and route the request to another function?

Ryan
@rnleach
Jun 02 2018 21:51
What does the signature of signup(...) look like? Are you taking the req object by reference?
@ozgurakkurt ^
Ryan
@rnleach
Jun 02 2018 21:57
First I think you would need to clone the uri path and request method as it appears from the documentation they are borrowed from the request object. Then do your match against those clones.
That would end the borrow.
fn router(req: Request<Body>) -> Return {
   let path = req.uri().path().clone();
   let method = req.ure().clone();
    match (method,  path) {
        (Method::POST, "/api/signup") => signup(req),
        (Method::GET, _) => index(),
        _ => not_found(),
    }
}
Does that work?