rust

Why can the Rust compiler break borrowing rules when using Rust 1.31?

爱⌒轻易说出口 提交于 2021-01-02 07:15:17
问题 I am studying Rust by Example and running code from the "Alias" page: struct Point { x: i32, y: i32, z: i32, } fn main() { let mut point = Point { x: 0, y: 0, z: 0 }; { let borrowed_point = &point; let another_borrow = &point; // Data can be accessed via the references and the original owner println!( "Point has coordinates: ({}, {}, {})", borrowed_point.x, another_borrow.y, point.z ); // Error! Can't borrow point as mutable because it's currently // borrowed as immutable. let mutable_borrow

Why can the Rust compiler break borrowing rules when using Rust 1.31?

风格不统一 提交于 2021-01-02 07:15:14
问题 I am studying Rust by Example and running code from the "Alias" page: struct Point { x: i32, y: i32, z: i32, } fn main() { let mut point = Point { x: 0, y: 0, z: 0 }; { let borrowed_point = &point; let another_borrow = &point; // Data can be accessed via the references and the original owner println!( "Point has coordinates: ({}, {}, {})", borrowed_point.x, another_borrow.y, point.z ); // Error! Can't borrow point as mutable because it's currently // borrowed as immutable. let mutable_borrow

How to store SQLite prepared statements for later?

我是研究僧i 提交于 2021-01-02 07:12:48
问题 Right now I have code that uses the rusqlite sqlite bindings to open a db connection and do a bunch of db operations in my application like this: extern crate rusqlite; use rusqlite::SqliteConnection; struct MyAppState { db: SqliteConnection, // ... pretend there's other fields here ... } impl MyAppState { fn new() -> MyAppState { let db = SqliteConnection::open(":memory:").unwrap(); MyAppState { db: db } } fn query_some_info(&mut self, arg: i64) -> i64 { let mut stmt = self.db.prepare(

How to store SQLite prepared statements for later?

微笑、不失礼 提交于 2021-01-02 07:11:26
问题 Right now I have code that uses the rusqlite sqlite bindings to open a db connection and do a bunch of db operations in my application like this: extern crate rusqlite; use rusqlite::SqliteConnection; struct MyAppState { db: SqliteConnection, // ... pretend there's other fields here ... } impl MyAppState { fn new() -> MyAppState { let db = SqliteConnection::open(":memory:").unwrap(); MyAppState { db: db } } fn query_some_info(&mut self, arg: i64) -> i64 { let mut stmt = self.db.prepare(

How can I match the root path with a Warp filter?

三世轮回 提交于 2021-01-01 09:04:30
问题 I have a simple web server using Warp that serves static files. I followed the examples in the Warp docs to get the following: let index_html = warp::path("index.html").map(handlers::index_html); // reply is handled in `handlers::` let script_js = warp::path("script.js").map(handlers::script_js); let routes = warp::get().and(index_html.or(script_js)); warp::serve(routes).run(([127, 0, 0, 1], 8000)).await; This returns files when requested from localhost:8000/index.html and localhost:8000

How can I match the root path with a Warp filter?

房东的猫 提交于 2021-01-01 08:58:05
问题 I have a simple web server using Warp that serves static files. I followed the examples in the Warp docs to get the following: let index_html = warp::path("index.html").map(handlers::index_html); // reply is handled in `handlers::` let script_js = warp::path("script.js").map(handlers::script_js); let routes = warp::get().and(index_html.or(script_js)); warp::serve(routes).run(([127, 0, 0, 1], 8000)).await; This returns files when requested from localhost:8000/index.html and localhost:8000

How can I match the root path with a Warp filter?

寵の児 提交于 2021-01-01 08:57:56
问题 I have a simple web server using Warp that serves static files. I followed the examples in the Warp docs to get the following: let index_html = warp::path("index.html").map(handlers::index_html); // reply is handled in `handlers::` let script_js = warp::path("script.js").map(handlers::script_js); let routes = warp::get().and(index_html.or(script_js)); warp::serve(routes).run(([127, 0, 0, 1], 8000)).await; This returns files when requested from localhost:8000/index.html and localhost:8000

Why does Rusqlite reject the Option type when executing a query?

一曲冷凌霜 提交于 2021-01-01 08:25:09
问题 I'm trying to insert CSV data into a SQLite database. stripe_id is optional, and so its type is Option<&str> . All the other fields are &str . When I use conn.execute to insert the values, they all insert correctly except for stripe_id , which throws an error saying it expects &str and not Option . I've searched the docs and Option<T> implements ToSQL , and when I've tried replacing my code with the Rusqlite example that includes an Option value, it throws the same error for the example code.

Write to child process' stdin in Rust?

做~自己de王妃 提交于 2020-12-31 05:54:05
问题 Rust's std::process::Command allows configuring the process' stdin via the stdin method, but it appears that that method only accepts existing files or pipes. Given a slice of bytes, how would you go about writing it to the stdin of a Command ? 回答1: You can create a stdin pipe and write the bytes on it. As Command::output immediately closes the stdin, you'll have to use Command::spawn . Command::spawn inherits stdin by default. You'll have to use Command::stdin to change the behavior. Here is

Write to child process' stdin in Rust?

柔情痞子 提交于 2020-12-31 05:51:49
问题 Rust's std::process::Command allows configuring the process' stdin via the stdin method, but it appears that that method only accepts existing files or pipes. Given a slice of bytes, how would you go about writing it to the stdin of a Command ? 回答1: You can create a stdin pipe and write the bytes on it. As Command::output immediately closes the stdin, you'll have to use Command::spawn . Command::spawn inherits stdin by default. You'll have to use Command::stdin to change the behavior. Here is