Better HN
topnewbestaskshowjobs
Log inSign up

greyblake

115 karma · joined Jul 9, 2016 (10y ago) · 52 submissions

Submissions

1.

Branchless Rust: Making a Filter 4x Faster by Removing an If(greyblake.com ↗)

293 points · by greyblake · 3mo ago · 110 comments

comment 7mo ago · link · parent

Short comic about AI systems and error handling.

3.

No Human Error (Comic)(nullwing.com ↗)

2 points · by greyblake · 7mo ago · 2 comments

comment 1y ago · link · parent

## What is nutype?

*nutype* is a procedural macro that adds sanitization and validation to newtypes, ensuring that values always meet your defined constraints.

## What’s new in v0.6.2

* *\[FEATURE]* Added `derive_unsafe(..)` for deriving arbitrary traits (requires enabling the `derive_unsafe` feature). * *\[FIX]* Upgraded Rust edition: *2021 → 2024*. * *\[FIX]* Improved error messages for `len_char_max` and `len_char_min`—they’re now clearer and easier to interpret.

## About `derive_unsafe`

With `derive_unsafe(..)`, you can now derive *any trait*, including third-party ones that nutype doesn’t recognize.

Unlike the safe `derive(..)`, this skips nutype’s internal checks. That means *you can accidentally break your validations at runtime*—for example, by enabling mutation via `DerefMut`.

To use this feature, add the `derive_unsafe` flag.

*Cautionary example:*

```rust use derive_more::{Deref, DerefMut}; use nutype::nutype;

#[nutype( derive(Debug, AsRef), derive_unsafe(Deref, DerefMut), validate(greater_or_equal = 0.0, less_or_equal = 2.0) )] struct LlmTemperature(f64);

fn main() { let mut temperature = LlmTemperature::try_new(1.5).unwrap();

    // This is exactly what you shouldn't do!
    *temperature = 2.5;

    // Validation rule? Violated.
    assert_eq!(temperature.as_ref(), &2.5);
} ```

*TL;DR:* `derive_unsafe` gives you freedom—but with that comes full responsibility. Use wisely.

5.

Nutype (rust crate) 0.6.2 released(github.com ↗)

1 points · by greyblake · 1y ago · 1 comment

6.

Alternative Blanket Implementations for a Single Rust Trait(greyblake.com ↗)

35 points · by greyblake · 1y ago · 3 comments

comment 1y ago · link · parent

Nutype is a proc macro that allows adding extra constraints like sanitization and validation to the regular newtype pattern. The generated code makes it impossible to instantiate a value without passing the checks. It works this way even with serde deserialization.

comment 4y ago · link · parent

CoffeeScript is a language without static typing. Despite this, CoffeeScript actually made a real revolution when it was introduced.

comment 4y ago · link · parent

You don't have to. You can have write a single component in ReScript and use it with the rest of the project written in JS or TS. See https://rescript-lang.org/docs/gentype/latest/introduction

comment 4y ago · link · parent

Whatlang demo webpage is implemented with seed: https://whatlang.org/

comment 4y ago · link · parent

+1

comment 4y ago · link · parent

There still "weak" points, where incorrect typing can be introduced, e.g. incorrectly written bindings. Regarding data from HTTP call in theory they can be cast to any type abusing `external` keyword which is meant for binings. But common and recommend approach is to write codes. Codec would perform all the necessary checks to ensure that the data are in correct shape to satisfy the type restrictions. You can see some examples here: https://github.com/greyblake/from-typescript-to-rescript/blo...

comment 4y ago · link · parent

Because a programming language is not a template engine.

comment 4y ago · link · parent

I agree, ReScript has no big adoption (hopefully yet), and that's the biggest disadvantage in comparison with TypeScript. But somebody has to do the first steps...

comment 4y ago · link · parent

> the use of decorators in even the most basic example

Can we agree that JSX is not a valid JS? So decorators are required indeed to simulate "JSX magic"

> no async/await.

As I mentioned, it's not an really an issue (although I though it will be). At least from my experience.

> You can't have two files with the same name in different folders??

This sucks indeed :)

The problem that those 20% corrupt the value of another 80% :/

comment 4y ago · link · parent

Thanks for your comment! I am aware of PureScript and even tried it a little bit 3-4 years ago, but was not aware that it has good interops too!
12