Fn :emacs: :agender: · @fn
12 followers · 384 posts · Server fnlog.page

**Carabao Dev Log**

After so much work, I finally converted the `sqlx` postgres adapter of `apalis` to `diesel` where untyped queries are only annoying if you don't have for it and the lack of support for async database triggers. I also had to dig deep and learn `tower` just to get it to compile.

All this for a background job processor. Much to clean up as well as determine the testing strategy.

I AM DEFINITELY STILL OKAY

#carabao #devlog #rust

Last updated 1 year ago

Fn :emacs: :ally: · @fn
10 followers · 255 posts · Server fnlog.page

**Carabao Dev Log**

I am heavily reworking and refactoring my database test creation with a builder pattern that feels pragmatic enough. Might have to make the skeleton into a macro again.

Anyway, I just found marking functions and structs `#[deprecated]` while refactoring to easily mark things I needed to change since `cargo clippy` issues a compilation warning. Not a novel approach I guess but just surprised I was able to use it.

Docs: doc.rust-lang.org/reference/at

#carabao #rust #dev_log

Last updated 1 year ago

Jacopo Ranieri · @jacoporanieri
46 followers · 180 posts · Server mastodon.uno
Fn · @fn
10 followers · 245 posts · Server fnlog.page

**Carabao Dev Log**

Good news, I learned that marking `actix::Actor` as `actix::SystemService` makes it much more convenient for my setup and with the tests. It is just strange it is not in the main documentation.

Bad news, I was wrong about the global database connection and had to create a flag/guard for a per-thread test pool (of 1) so that the tests are consistent. The things I do for a test harness.

`actix::registry::SysemRegistry `: docs.rs/actix/latest/actix/reg

#carabao #rust #dev_log

Last updated 1 year ago

Fn · @fn
10 followers · 234 posts · Server fnlog.page

**Carabao Dev Log**

Just found out that `cargo fmt` can be used to format `Cargo.toml` files but the PR for it is not yet merged. Not sure I agree with the actual formatting, but I do want more a standard method and tool.

Github Comment: github.com/rust-lang/rustfmt/p

#carabao #rust #dev_log

Last updated 1 year ago

Fn · @fn
9 followers · 231 posts · Server fnlog.page

**Carabao Dev Log**

So creating an event bus with `actix` did involve some `macro_rules`. The type safety though of handlers is fascinating where each message must have a handler instead of letting it silently ignored.

On the testing side, I am surprised that testing database connections across multiple actors with their own pools still produce a consistent test result somehow as if they use a global test connection. 🤷

#carabao #rust #dev_log

Last updated 1 year ago

Fn · @fn
9 followers · 226 posts · Server fnlog.page

**Carabao Dev Log**

I wish there was an quick event bus solution for `actix` where I am writing so many `impl Handler` to broadcast messages. If anybody wants to make that where you can just maybe register an `Actor` then just write the `Handler`s would be great. Yet I do think it might not be possible without some `macro` magic which would also be a dealbreaker.

Although this makes me reflect the things I neglected while working with /Elixir/ and its global registry.

#carabao #rust #dev_log

Last updated 1 year ago

Fn · @fn
1 followers · 176 posts · Server fnlog.page

**Carabao Dev Log**

Writing tests for the OAuth entities now since I feel it is stable now. My current problem is now running a `diesel` transaction within a transaction since test connections use a test transaction via `conn.begin_test_transaction()`. Thankfully this is easy to resolve:

```
conn.begin_test_transaction();

/// DOES NOT WORK
/// conn.build_transaction().run(...);

/// WORKS
conn.transaction(...);
```

#carabao #rust #dev_log

Last updated 1 year ago

Fn · @fn
1 followers · 174 posts · Server fnlog.page

**Carabao Dev Log**

Still fixing up my PR for adding a missing OAuth `client_credentials` but for now I came across this footgun with filtering `NULL` database fields with `diesel`. Instead of `field.eq(None)`, it was actually `field.is_null()` which kinda feels a little bad on the Rust side, but makes sense in SQL. (The fragment `table.field = NULL` is not the same as `table.field IS NULL`.)

Issue: github.com/diesel-rs/diesel/is

#carabao #rust #dev_log

Last updated 1 year ago

Fn · @fn
1 followers · 168 posts · Server fnlog.page

**Carabao Dev Log**

I am so blind for not noticing there were async bindings for the critical traits in `oxide_auth` named `oxide_auth_async`. Would have saved me time from finding ways to run async functions inside non-async functions. Still have to integrate it a bit later though.

Github Issue: github.com/HeroicKatora/oxide-
`oxide_auth_actix`: docs.rs/oxide-auth-actix/lates

#carabao #rust #dev_log

Last updated 2 years ago

Fn · @fn
1 followers · 166 posts · Server fnlog.page

**Carabao Dev Log**

Refactoring my database operation to have an macro generated async version from a sync version instead of just all async really helped although I still question if this is healthy.

```
#[with_async]
pub fn get_by_id(conn: &mut PgConnection, id: &Uuid) -> AnyhowResult<Entity> { ... }

/// Generates a $name_ident async version
pub async fn get_by_id_async(...)
```

#carabao #rust

Last updated 2 years ago

Fn · @fn
1 followers · 162 posts · Server fnlog.page

**Carabao Dev Log**

At last, I was able to integrate the OAuth2 library(`oxide_auth`) for my `actix-web` project. So many days and so much code to finally just get an access bearer token. 🥳 😭

Still have some more work and cleanup to do but I do wonder if there is an easier OAuth2 server library integration.

`oxide_auth`: github.com/HeroicKatora/oxide-

#carabao #rust

Last updated 2 years ago

Fn · @fn
1 followers · 119 posts · Server fnlog.page

**Carabao Dev Log**

Revelation, I was trying to make my error wrapping better. In particular, I was trying to convert a missing database entry error into an application specific error and doing `convert(action.await?)` feels lacking.

So I tried doing a simple `Extension Traits` for `anyhow` errors and it just feels good doing `action.await.not_found("app_id")?`.

Extension Trait: xion.io/post/code/rust-extensi
Anyhow Error: docs.rs/anyhow/latest/anyhow/s

#carabao #rust #dev_log

Last updated 2 years ago

Fn · @fn
1 followers · 108 posts · Server fnlog.page

**Carabao Dev Log**

Almost close to finishing my initial crating refactoring. I came across this strange macro issue:

`type `fn(String) -> Wrapper {Wrapper}` is private
private type`

The issue is that I forgot to add `pub` to the inner wrapper type but the error was hard to understand behind a macro error.

The debugging tactic I used is to copy the output of `cargo expand` and get a better compiler error which took me longer to realize.

github.com/dtolnay/cargo-expan

#carabao #rust #dev_log

Last updated 2 years ago

Fn · @fn
1 followers · 106 posts · Server fnlog.page

**Carabao Dev Log**

So I refactored my models to use the new typed de/serialization strategy and it feels good keeping the `diesel` dependency in one subcrate.

Sadly for ad-hoc query types like returning a few fields, I have to use the new wrapper types then convert them to its intended type which is a minor inconvenience.

The last gotcha is manually implementing `Nullable` since it is not automatically derived for custom types which is hard to detect.

Still a win

#carabao #rust #dev_log

Last updated 2 years ago

Fn · @fn
1 followers · 105 posts · Server fnlog.page

**Carabao Dev Log**

OMG, `diesel` has `deserialize_as` and `serialize_as` which helps me in writing less macros and implementing less types. I need to rethink my approach here.

Insertable: docs.diesel.rs/master/diesel/p
Queryable: docs.diesel.rs/master/diesel/d

#carabao #rust #dev_log

Last updated 2 years ago

Fn · @fn
1 followers · 104 posts · Server fnlog.page

**Carabao Dev Log**

So I am in the process of splitting my project into multiple crates and it is somewhat relaxing and cathartic. Sadly, I am running into safe type conversions that are hard to refactor. I may have to bite the bullet to allow `unsafe` just for type conversions.

#carabao #rust #dev_log

Last updated 2 years ago

Fn · @fn
1 followers · 102 posts · Server fnlog.page

**Carabao Dev Log**

At last, the OAuth2 intergration of `oxide-oauth` is working with `code` response type. I have been trying to figure out how it works and took so long. 😭 Just so happy it works but I have to add some protections like CSRF and so on.

#carabao #rust #dev_log

Last updated 2 years ago

Fn · @fn
1 followers · 100 posts · Server fnlog.page

**Carabao Dev Log**

So I finally figured out why rendering an HTML body with `Yew SSR` then passing it to an `Askama template` never renders properly. It was because the `Askama` by default HTML escapes by default and I just had to disable that. 😅

```rust
#[derive(Template)]
#[template(path = "page.html", escape = "none")]
pub struct PageTemplate<'a> { }
```

#carabao #rust #dev_log

Last updated 2 years ago

Fn · @fn
1 followers · 90 posts · Server fnlog.page

**Carabao Dev Log**

Cleaning up some test code and I realized that pool connections were not started in a transaction. If I did try to start a transaction, I get a transaction in a transaction error.

With `r2d2`, a pool can be configured to do this on connection checkout which is neat.

Snippet: pastebin.com/jLtuPKYP
r2d2: docs.rs/r2d2/latest/r2d2/trait

#carabao #rust #dev_log

Last updated 2 years ago