#deccer+rust=?

269 messages · Page 1 of 1 (latest)

sturdy tangle
#

installation went not smoof already, good start, rust

lament kiln
#

inshallah we must hail the borrow checker

#

(idk I don't speak rust)

sturdy tangle
#

se fuck is IntellijRustDollarCrate

sturdy iron
#

Was

sturdy tangle
#

jebus

#

expanded println once

sturdy iron
#

I have no idea what you are doing to see these arcane objects

#

Oh

#

Yeah don’t do that

sturdy iron
#

May I interest you in a vulkan abstraction library for rust kekw

sturdy tangle
#

no

sturdy iron
sturdy tangle
#

rust feels like a pain in the ass already

#

and i cant even do gl halfproperly

sturdy iron
lament kiln
#

Why do we have nogl but not :novk:

sturdy iron
#

Because vk is good

lament kiln
#

It's time to make a new suggestion

sturdy iron
#

no

lament kiln
#

I missed reading the standard btw

manic hedge
#

Using Rust with gl is fiiiine (I have Stockholm Syndrome).

lament kiln
sturdy tangle
#

hmm

#

does clion support all that library/module nonsense too?

#

with the rust plugin that is

sturdy iron
#

Wdym

#

Probably

sturdy tangle
#

made new folder lib/lib-graphics with Cargo.toml and a lib.rs

#

lib.rs has a module with the same name in it graphics

#

but from main.rs i was expecting that i can do use graphics; and instantiate whatever is declared in graphics module

#

: )

#

and have the rustplugin add graphics to any dependency like intellij-intellisense ususally does

sturdy iron
#

I don’t think it does that no

#

But you probably just want submodules, not entire sub crates

#

So src/graphics/mod.rs

#

That way you don’t need to manage dependencies between each module

#

If you do want that (I do this it does have some advantages), you may want to look into cargo workspaces instead

sturdy tangle
#

like this?

backyard
├── Cargo.lock
├── Cargo.toml
└── src
    ├── garden
    │   └── vegetables.rs
    ├── garden.rs
    └── main.rs
sturdy iron
#

Thats possible too

#

It does the same, but I find it less intuitive

sturdy tangle
#

less intuitive were my fist thoughts

sturdy iron
#

This is equivalent to replacing garden.rs with garden/mod.rs

sturdy tangle
#

yeah i went with your way

#

hmm i then assumed i can just do

#
use graphics;

fn main() {
    let x = Thing(); // thing is in graphics module
}
#

or have the rust plugin resolve it for me 😉

sturdy iron
#

use graphics just imports the module, you can’t write the unqualified name of the contents yet

#

But yes I do that too

#

use graphics::Thing or let x = graphics::Thing::new()

sturdy tangle
#

yep wanted to peek into your code : )

sturdy iron
#

I just let clion import what I need lol

#

Usually I don’t qualify names at all

#

Idk if that’s good practice but it seems to hold up with what I’ve seen

sturdy tangle
#

hmm

#

thats the module

#
mod graphics {
    struct Device {}

    impl Device {
        fn CreateTexture2D(texture2DDescriptor: Texture2DDescriptor) -> Texture2D {
            return Texture2D {};
        }
    }
}
sturdy iron
#

pub

sturdy tangle
#

ah

sturdy iron
#

Its private by default

sturdy tangle
#

pub mod neh?

sturdy iron
#

Also yes

#

But the contents too

#

Everything is always private by default

manic hedge
#

Pub everything KEKW

sturdy tangle
#

kkkk

lament kiln
#

deccer let me know how annoying the Rust compiler is

sturdy iron
#

the thing is usually it yells at u but also tells u how to fix it

sturdy tangle
#

it doesnt thats the thing

#

just gives totally unrelated hints

#

unless they are just named like shit

#

i removed pub mod graphics, just left all the things in there

#

but then it probably needs to stay

sturdy iron
#

oh wait

#

in graphics/mod.rs you dont need to declare mod graphics

#

the file itself is already the module

sturdy tangle
#

i cant even rename mod.rs to anything else 😄

#

i see

#

that makes some sense

sturdy iron
#

Yeah its a reserved name, kinda like main.rs or lib.rs

sturdy tangle
#

yep i think i read that in the docs

#

im so used to c# and 1 file per type

sturdy iron
#

rust encourages you to group types logically

sturdy tangle
#

hrm i cant load any github page

sturdy iron
#

huh

#

is github dead again

sturdy tangle
#

i can load my profile

#

but i cant open your page for instance

sturdy iron
#

its a bit slow for me but its working

sturdy tangle
sturdy iron
sturdy tangle
#

now it werks

sturdy iron
#

weird

sturdy tangle
#

ah its slow again

#

who knows, maybe the kids who attacked gitlab recently now try github somehow

jolly geode
#

me seeing the title of this thread

sturdy iron
sturdy tangle
#

i know a guy irl, who looks exactly like that man 😄

sturdy tangle
#

fooking github

sturdy iron
#

what are you looking for

#

maybe i can clone it and zip it your way

lament kiln
#

Discord and GitHub seem to be having some issues

sturdy iron
#

theyre fine for me

lament kiln
#

They're very slow for me, perhaps it's just me

sturdy tangle
#

oh god

#

it finally built

#

and i had to add a self param 🤮

sturdy iron
#

yes

#

methods without self are static

sturdy tangle
#

that is ugly

sturdy iron
#

is it really

#

its more explicit

sturdy tangle
#

why is self not a builtin in instance methods

sturdy iron
#

the reason is you also use it to specify if the method can mutate self or not

lament kiln
#

C# did it right

sturdy tangle
#

i suppose its coming from the fact that declaration and definition of "classes" is separate ... struct Foo { } impl Foo { }

lament kiln
#
public void Thing(this Self stuff) {
}```
#

You can even rename the this parameter, how cool is that

sturdy tangle
#

thats almost correct c#, method must be static there, and then its an extension if it lives in a static class

sturdy iron
#
struct Foo {}

impl Foo {
  fn bar() {} // static
  fn baz(&self) {} // const method
  fn baw(&mut self) {} // non-const method
  fn bax(self) {} // moves out of self
}
sturdy tangle
#

ok fair

#

its weird still

#

but thats just me

#

from using rust for 4mins 😄

sturdy iron
#

yeah imo a lot of things seem weird initially but do make sense in the big picture in the end

lament kiln
#

The hell does move out of self mean

sturdy tangle
#

that you when mama kicks you out

lament kiln
#
struct X {
    void x() &&;
}```
#

Like this?

sturdy iron
#

kind of

#

imagine it as calling bar(std::move(thing))

#

but in rust moves are destructive, so thing is no longer accessible after calling that

sturdy tangle
#

imagine calling static functions static 😄

lament kiln
#

I fail to see how this is useful

sturdy tangle
#

so i have to think more c like rather than c++ (and classes) like

sturdy iron
#
let foo = Foo {};
foo.bax();
// using foo is now a compiler error
sturdy iron
lament kiln
#

Maybe for stuff like optional?

sturdy iron
#

with build() moving out of self and returning the target object

sturdy tangle
#

thats a weird explanation, self is the builder itself, and build() returns the object to be build

sturdy iron
#

you also are not allowed to move out of fields inside &(mut) self functions

#

as a practical example

sturdy tangle
#

again please excuse my ignorance

lament kiln
#

I c (read: I see)

sturdy iron
#

I have IncompleteCommandBuffer which allows recording commands

#

It has a finish(self) method

#

Which calls vkEndCommandBuffer and returns a new CommandBuffer that doesnt expose methods for recording but can be submitted

lament kiln
sturdy iron
#

this guarantees at compile time that

  • you cannot record commands after vkEndCommandBuffer
  • you cannot submit unfinished command buffers
sturdy iron
lament kiln
#

But that doesn't make any sense, what if I want to use the same IncompleteCommandBuffer to record the next pass frame

sturdy iron
#

you mean the next frame?

#

you dont finish() between passes

#

Only when youre done recording

lament kiln
#

Yeah, frame lol

sturdy iron
#

I have some internal recycling going on

#

But in general in my lib you just allocate a new command buffer

#

The lib might re-use an old one, I haven't implemented that yet but it's worth considering

lament kiln
#

Yet another L for destructive moves smh

sturdy iron
#

a W for destructive moves

#

the command buffer isnt destroyed

lament kiln
#

But you can't use it anymore

jolly geode
#

It's in another castle

sturdy iron
#

sure but doing so is an error anyway

#

if you use it before its done executing you get a sync bug

sturdy tangle
#

i think ill just stay on my c# island, and keep my small brain safe

sturdy iron
#

if you use it after its fine but you have to reset it first

lament kiln
#

I do that yes

sturdy iron
#

I decided not to expose the possibility of this mistake

lament kiln
#

wait_fence + reset

sturdy iron
#

by just telling you to cope and ask for a new one kekw

sturdy tangle
#

: )

sturdy iron
#

the library might do some pooling in the future, thats not a bad idea tbh

lament kiln
sturdy iron
#

but in general a frame looks a bit like

let cmd = exec.on_domain::<All>()?;
let cmd = graph.record(cmd, &bindings, &mut pool, None, &mut ())?;
let cmd = cmdfinish()?;
let mut batch = exec.start_submit_batch()?;
batch.submit_for_present(cmd, &ifc, pool)?;
Ok(batch)
sturdy iron
#

this handle can be pooled internally

#

I could store a Pooled<vk::CommandBuffer> instead and thats it

lament kiln
#

Meh

sturdy iron
#

is the fact that you need to allocate a new command buffer each frame throwing you off

lament kiln
#

No, it's the destructive move that me no likey

sturdy iron
#

consider this C++ code

#
auto foo = FooWithImportantInternalState {};
bar(std::move(foo));
// accessing foo might now be UB, depending on how its move
// constructor is implemented
#

From SO

lament kiln
#

Sure foo is in an unspecified state

#

But we all know that strong and powerful C++ developers either put foo in a default-initialized state for trivial and default constructible types or in a zero-initialized state for POD and non-default-constructible types

jolly geode
#

standard lib containers are guaranteed to be in a valid state at least

lament kiln
#

If you don't put foo in a well-defined state you deserve to SIGSEGV KEKW

sturdy iron
#

Also, if you want to re-use the foo name in Rust, you can just rebind it: ```rs
let foo = Foo {};
foo.move_me();
let foo = Foo {}; // ayy we back

lament kiln
#

Redeclaration? wut

sturdy iron
#

shadowing

sturdy tangle
#

thats a new instance, innit?

sturdy iron
#

yeh

lament kiln
#

oh god

sturdy iron
#

it just hides the old one

sturdy tangle
#

w🇹🇫

sturdy iron
#

now i get that this looks like a huge ick

#

BUT

#

in typical rust code, this is actually a good thing

#

for example

#
let foo: Option<T> = get_an_optional_value();
if let Some(foo) = foo {
  // use foo
} else {
  // dont use foo
}
#

Having to rename the initial foo to foo_opt would be quite ugly

sturdy tangle
#

how to get the value out of your monad

jolly geode
#

Some(body)

lament kiln
#

Once(told)

sturdy iron
#

smh not using std::sync::Once

sturdy tangle
#

Once reads like dunce almost

jolly geode
#

std::think::Dunce

sturdy tangle
#

hehe

lament kiln
#

sir penguin

sturdy iron
#

Yessir

lament kiln
#

How do you do this in rust:

alignas(max_align) unsigned char my_garbage_ok_dont_ask[max_size];
auto* ptr = new (my_garbage_ok_dont_ask) T();
ptr->execute_order_66();
ptr->~T();```
sturdy iron
#

unsafe

lament kiln
#

Well yes, I guess this is not very safe for Rust KEKW

sturdy iron
#

There might be a way to do this that’s not UB

#

Maybe the following:

let buffer = Box::new_uninit::<[u8]>(size);
let ptr = Box::into_raw(buffer);
let foo = ptr as *mut Foo;
*foo = Foo {};
let foo = Box::from_raw(foo);
let foo = foo.assume_init();
foo.execute_order_66();
drop(foo);
jolly geode
#

how do you make a memory allocator in rust? impossible mode: safe rust only

sturdy iron
#

I typed this on mobile so i don’t know if this compiles but

lament kiln
#

I like how I tell rust assume_init

#

spoiler:

#

IT'S A LIE

sturdy iron
#

That’s a function of MaybeUninit<T>

#

(Its obviously unsafe)

lament kiln
#

That doesn't call Foo's constructor though does it?

sturdy iron
#

I constructed a Foo

#

*foo = Foo {}

lament kiln
#

Ah yes

#

I somehow missed that

sturdy iron
#

This is subtly different from placement new in that this foo is created on the stack and then moved into the pointed to value

#

But that’s usually not important

#

Box<T> is unique_ptr<T> btw

lament kiln
#

Looking at my C++ code I don't wonder how much unsafe I should have

#

I wonder how much safe instead

#

I'd be quicker to just do unsafe {} the whole program KEKW

sturdy iron
#

There’s a neat tool that prints all unsafe lines in a c++ program

lament kiln
#

Pog

sturdy iron
#

Its called cat

lament kiln
#

do tell me

#

Ah

sturdy iron
#

(Joke stolen from jaker)

lament kiln
#

I thought it was some sort of potential ubsan

sturdy iron
lament kiln
#

Would be cool ngl

sturdy iron
#

Me too

#

Yeah

lament kiln
#

Mfw a simple + is potentially undefined due to integer promotion

sturdy iron
lament kiln
#

You just need to embrace UB instead of reject it

jolly geode
sturdy tangle
#

Jake stolen from Joker

sturdy tangle
#

crate::hint::black_box(()); 😄

vital oak
#

deccer going beast mode?

sturdy tangle
#

rust is hardly a beast

sand ermine
#

👀

sturdy tangle
#

: )

manic hedge
#

Rust isn't a difficult language.