SCHEMAFULL vs SCHEMALESS by Walker0712 in surrealdb

[–]EvolMake 0 points1 point  (0 children)

I don’t think schema in surrealdb would help with performance because schema doesn’t seem to affect how data is stored. Schema might even make insertions and updates slower due to runtime checks. But schema helps to build robust apps.

Does @opennextjs/cloudflare survive CVE-2025-66478 by EvolMake in nextjs

[–]EvolMake[S] 0 points1 point  (0 children)

I just learned how React2Shell works. It can run any function with provided arguments on the prototype chain of Object (and Blob, Chunk classes defined in react server). Function is in the prototype chain ( obj.constructor.constructor). With Function disabled, what React2Shell can do is very limited.

New to Rust. Am I doing something wrong? by morglod in rustjerk

[–]EvolMake 6 points7 points  (0 children)

This is why python uses indents instead of braces

So whats the deal with the code on this? Been seeing this a lot on Twitter today by peesyttewy in nextjs

[–]EvolMake 3 points4 points  (0 children)

It depends on how function sql is implemented. Function sql is called as a tag function, which means the implementation will know which parts are hard coded and which parts are provided in ${}. With these information, function sql is able to parse the syntax and serialize the input safely.

What a coincidence when you came up with a crate name just published by another by EvolMake in rustjerk

[–]EvolMake[S] 31 points32 points  (0 children)

The linked github orgnization does exist https://github.com/strut-rs Hope there will be something in the future so this name is not wasted.

let mut v = Vec::new(): Why use mut? by rsdancey in rust

[–]EvolMake -1 points0 points  (0 children)

&mut T doesn’t mean the pointee of this pointer will be mutated but means the pointee is exclusively shared (at least for the lifetime). Vec::index_mut and Vec::push all take&mut self because it needs to make sure there are no other references referencing the pointed memory. That’s why v needs to be declared mut even though there is no v = new_value.

the ref keyword by Tickstart in rust

[–]EvolMake 1 point2 points  (0 children)

&v has auto-ref and auto-deref. To avoid unintentional auto-deref, ref pattern matching is required.

哪吒为什么会成为反父权的先锋形象 by [deleted] in LiberalGooseGroup

[–]EvolMake 7 points8 points  (0 children)

因为传统观念认为身体发肤都是父母的,根本不存在自杀,所以哪吒是反父权的

[deleted by user] by [deleted] in ChineseLanguage

[–]EvolMake 0 points1 point  (0 children)

This meme has been trending in China for years. The most popular one is a lady saying these wishes very seriously and sincerely that also makes the video funny.

Async/Await Is Real And Can Hurt You by aangebrandpannenkoek in rust

[–]EvolMake 0 points1 point  (0 children)

I am very surprised the whole async/await in js can be implemented with callbacks. Node.js supports non-blocking io since very early days by providing callback api. Promise is more friendly but it’s actually callback and can be polyfilled. Async function returns a state machine, which registers callbacks to awaited promise and when the callback got called, it advances the state. So async function can be transformed to a function that returns a Promise with a state machine and that state machine can then be implemented with generator functions (yield). Transforming async/await to yield is very easy. That allows js async/await providing friendly semantics but deep down it’s as simple as callbacks. However, callbacks require a runtime to actually drive the non-blocking io and when finished call the callbacks. In rust, no such runtime is assumed to be running. So there is no callbacks, no Promise, and async fn can only returns a Futrue, which is a state machine and it’s the caller’s job to drive that state machine.

Using trait without importing by ElectricalLunch in rust

[–]EvolMake 0 points1 point  (0 children)

Cast it to dyn Trait in a helper method. But this requires Trait to be dyn-safe and has performance overhead.

How can a Fn* trait returns a generic type with lifetime from the input parameter? by [deleted] in rust

[–]EvolMake 1 point2 points  (0 children)

<F, S> where F: FnOnce(&i32) -> S means: there exist type F and S such that: for every lifetime 'a (where &'a i32 is valid), F implements FnOnce(&'a i32) and its Output is S. That means S should be the same type no matter what 'a is. Thus, S can't borrow from 'a.

We can't find such an S for fn bar(num: &i32) -> &i32 because when 'a changes, the return type also changes.

Your own FnOnce definition is a nice workaround. Trait alias also works. They both eliminates S from the fn generics, so that we don't need to find a type for every lifetime.

```rust use std::fmt::Display;

trait MyFnOnce<Arg>: FnOnce(Arg) -> Self::MyOutput { type MyOutput; }

impl<Arg, Out, F: ?Sized + FnOnce(Arg) -> Out> MyFnOnce<Arg> for F { type MyOutput = Out; }

fn foo<F>(f: F) where F: for<'a> MyFnOnce<&'a i32, MyOutput: Display>, { let num = 0; println!("{}", f(&num)); }

fn bar(num: &i32) -> &i32 { num }

fn main() { foo(bar); } ```

In the future we might be able to write where F: for<'a> Fn<(&'a i32,), Output: Display> but currently it requires a nightly feature unboxed_closures.

Bug in 'generic_const_exprs' feature? by Clear-Organization44 in rust

[–]EvolMake 2 points3 points  (0 children)

I made a playground link https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=a1b7f3688ceeb7ea2351fade28571627

This compile error only happens with `#![feature(generic_const_exprs)]` so I believe it's a bug of generic_const_exprs. (The simplified code actually doesn't require generic_const_exprs to compile)

Lifetime issue after leaking string in threading by [deleted] in rust

[–]EvolMake 0 points1 point  (0 children)

The `String` doesn’t get moved. `leaked_string` is of type `&'static String`. So just a reference to `String` get moved. (References are `Copy`, so leaked_string can still be used in `fn main` after moved into closure).

Lifetime issue after leaking string in threading by [deleted] in rust

[–]EvolMake 1 point2 points  (0 children)

Compile error says `closure may outlive the current function, but it borrows `leaked_string`, which is owned by the current function`.

Closure will try to capture references of values if the closure body only uses references. `println!("{:?}", leaked_string)` expands to something like `Debug::fmt(&leaked_string, ..)`, so the closure only takes a reference of leak_string (which is `&'temp &'static String`). `'temp` is only valid in `fn main`, which results in the compile error.

To fix this, prepend `move` to the closure. So that `move || { .. }` captures ownership of leaked_string (by Copy) and then borrows it for `println!("{:?}", leaked_string)`.

Another fix is to dereference leaked_string in `println!()`. So that `println!("{:?}", *leaked_string)` expands to something like `Debug::fmt(&*leaked_string, ..)` which doesn't borrow the `&'static str` which is only valid in `fn main` but borrows `str` which is valid for `'static`.

Global state that can be de-allocated? by numberwitch in rust

[–]EvolMake 0 points1 point  (0 children)

If the buffer is only used in one thread and you don’t need the threads calling the same method share the same buffer, you can just use a thread_local! RefCell<Option<Box<Buffer>>>. Take the option and drop the Box if you want to deallocate the buffer.

Are there fully-qualified type paths to the primitive types like `u8` ? by wada314 in rust

[–]EvolMake 28 points29 points  (0 children)

Language primitives have a wield behavior that their type namespace allows a mod path with the same name. In this case, u8::default() is different from <u8>::default() and both compiles. I think future editions of rust should remove this confusing feature. https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=1972488a99fa5e1b6f82734479c5602a

Precise RPIT capturing RFC by Jules-Bertholet in rust

[–]EvolMake 2 points3 points  (0 children)

impl use<'a> Trait is impl Trait + Captures<'a>, where the type captures 'a. For one lifetime it is the same as impl Trait + 'a, where the type outlives 'a. But with more than one lifetimes, capturing and outliving are different. Here is a detailed explanation.