Skip to content

Instantly share code, notes, and snippets.

fn insert_junction_table<Table, Data>(
conn: &PgConn,
insert: qb::IncompleteInsertStatement<Table, Data>,
dat: Data,
) where
Table: qs::Table,
Table::FromClause: qb::QueryFragment<pg::Pg>,
Data: Insertable<Table> + qb::QueryFragment<pg::Pg>,
Data::Values: qb::QueryFragment<pg::Pg> + diesel::insertable::CanInsertInSingleQuery<pg::Pg>,
{
use diesel::pg;
use diesel::query_builder::BoxedSelectStatement;
use diesel::query_source::QuerySource;
use diesel::sql_types as st;
fn heckin_abstraction_with_diesel<QS>(
conn: &PgConn,
select: BoxedSelectStatement<(st::Text, st::BigInt), QS, pg::Pg>,
) -> HashMap<String, i64>
where
QS: QuerySource,
type SqlType = <(diesel::sql_types::Text, diesel::sql_types::BigInt) as Expression>::SqlType;
type BoxedQuery<'a> = cargofox::schema::analyze_metadata_authors::BoxedQuery<'a, Pg, SqlType>;
fn lookup<E>(conn: &PgConn, e: E) -> HashMap<String, i64>
where
E: AsExpression<(Text, BigInt)>
+ diesel::expression::SelectableExpression<cargofox::schema::analyze_metadata_authors::table>
+ diesel::query_builder::QueryFragment<Pg>
+ diesel::query_builder::QueryId,
E::Expression: BoxableExpression<ama::analyze_metadata_authors, Pg>,
{

Forgive me. I tried to leave it there, I really did. But I can't resist the urge to just, you know, try to fix something. So I wanted to try to see if it was possible to make your Rust frustrations (Rustrations?) smoother.

First: braindead error incantation.

#[macro_export]
macro_rules! raise {
error[E0271]: type mismatch resolving `<diesel::query_source::joins::JoinOn<diesel::query_source::joins::Join<schema::crate_versions::table, schema::crates::table, diesel::query_source::joins::Inner>, diesel::expression::operators::Eq<diesel::expression::nullable::Nullable<schema::crate_versions::columns::crate_id>, diesel::expression::nullable::Nullable<schema::crates::columns::id>>> as diesel::query_source::AppearsInFromClause<schema::analyze_cratefile::table>>::Count == diesel::query_source::Once`
--> cargofox/src/lib.rs:250:10
|
250 | .select((
| ^^^^^^ expected struct `diesel::query_source::Never`, found struct `diesel::query_source::Once`
|
reqwest v0.9.5 (/home/icefox/tmp/reqwest)
├── base64 v0.10.0
│ └── byteorder v1.2.7
├── bytes v0.4.11
│ ├── byteorder v1.2.7 (*)
│ └── iovec v0.1.2
│ └── libc v0.2.45
├── encoding_rs v0.8.13
│ └── cfg-if v0.1.6
├── futures v0.1.25
Oct 31 19:53:08.970 TRCE outgoing
Oct 31 19:53:08.973 TRCE initial dcid, value: c4c4b86c8d97f9772b4fb48883fae4d90aa0
Oct 31 19:53:08.977 TRCE sending handshake packet, pn: 230150011
Oct 31 19:53:08.977 TRCE STREAM, fin: false, len: 240, off: 0, id: 0
Oct 31 19:53:08.977 TRCE timer start, time: 10.004035s, timer: Idle
Oct 31 19:53:08.977 TRCE timer start, time: 204.035ms, timer: LossDetection
Oct 31 19:53:08.984 TRCE connection got packet, len: 123, connection: 8b1496bc46f21643
Oct 31 19:53:08.984 TRCE got remote connection id, remote_id: 73aa6d4103c0706b, connection: 8b1496bc46f21643
Oct 31 19:53:08.984 TRCE packet authenticated, pn: 3503076676, connection: 8b1496bc46f21643
Oct 31 19:53:08.984 TRCE got ack, ranges: [230150011..230150012]
47.12% mars mars [.] <mars::scene::sphere::Sphere as mars::scene::hitable::Hitable>::hit ◆
12.01% mars mars [.] mars::color ▒
6.90% mars mars [.] mars::render_thread ▒
5.88% mars mars [.] mars::math::random_in_unit_sphere ▒
4.13% mars mars [.] <mars::scene::material::Lambertian as mars::scene::material::Material>::scatter ▒
3.92% mars mars [.] <mars::scene::hitable_list::HitableList as mars::scene::hitable::Hitable>::hit ▒
3.17% mars mars [.] <rand::prng::hc128::Hc128Core as rand_core::block::BlockRngCore>::generate ▒
3.08% mars mars [.] <mars::scene::material::Deile
[2018-10-19 17:38:41][INFO][worlddat::peer] Bootstrap peer: Some("quic://127.0.0.1:4433/")
thread 'main' panicked at 'already borrowed: BorrowMutError', libcore/result.rs:945:5
stack backtrace:
0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
1: std::sys_common::backtrace::print
at libstd/sys_common/backtrace.rs:71
at libstd/sys_common/backtrace.rs:59
2: std::panicking::default_hook::{{closure}}
at libstd/panicking.rs:211
[2018-10-19 17:23:20][TRACE][worlddat::peer] Trying to shut down stream
thread 'main' panicked at 'unknown stream', libcore/option.rs:989:5
note: Run with `RUST_BACKTRACE=1` for a backtrace.
Thread 1 "worlddat" hit Breakpoint 1, quinn_proto::connection::Connection::close (self=0x7ffff7708008, ctx=0x7ffff765b378, now=31534,
conn=ConnectionHandle = {...}, error_code=0, reason=Bytes = {...})
at /home/icefox/.cargo/registry/src/github.com-1ecc6299db9ec823/quinn-proto-0.1.0/src/connection.rs:2097
2097 State::Established(_) => State::Closed(state::Closed {
(gdb) bt
#0 quinn_proto::connection::Connection::close (self=0x7ffff7708008, ctx=0x7ffff765b378, now=31534, conn=ConnectionHandle = {...},