Show older

anyway the part of the puzzle that I think I inadvertently left out of this thread is that I'm starting out learning rust by modifying an existing rust program, not in writing anything my own.

So there's a lot of "how the fuck does this work?" and having to read the source until I figure out what keywords I need to google

which is a lot easier when it's a word like "Result" or "anyhow with_context" and not "?"

(I think I figured out ? now, you don't need to provide any help. that was just an example)

it's working and I am learning rust, it's just very much the same vibes as learning to swim by having your grandpa fling you into the deep end

I should probably figure out what these & symbols mean

is there any ide that's recommended for doing rust? I'm currently just using Sublime Text which has some syntax highlighting but not much else.
Is there good support in VS.code or something?

oh now now I have to understand how implementing iterators works

okay apparently the problem is that this code implements iterator for "foobar", but not for "&foobar"

I'm not sure what the fuck that means

but I do like that it's "for more information, run "rustc --explain E0277"

I grew up on the TRS-80 which just gave you ?ER when something was wrong. What, specifically, was wrong? Fuck you, that's what.

if you look closely you can spot where the article is supposed to be

type Item = &'a str;

this is valid syntax and not someone sneezing into a keyboard?

okay I think the problem is something like: this code originally implemented IntoIterator which was fine because it was backed by a std::vec so it could just use that iterator.
but now it's not a std::vec so it doesn't work.

except it still kinda is. so... it doesn't work

now I gotta figure out what a tuple struct is.

it seems to be a regular struct except your fields don't have names?

sometimes I worry I'm not awake & sober enough to understand this.

sometimes I worry I've never been that awake and sober. I don't know if I've ever been so knurd I could actually understand this

and someone mentioned cargo-mommy to me and now I'm having my brain broken by that.

PROGRAMMING IS HARD ENOUGH ALREADY WHY DID YOU HAVE TO GO AND MAKE IT HORNY?

okay, enough people being horny about programming languages and shooting at former presidents.
this code still can't iterate

so (and I'm writing this primarily to rubber-duck my own understanding of it, rather than specifically asking questions, though feel free to speak up if you think you can help):

I have a tuple struct called "Commands" that contains an std::vec of "Command" structs.
I'm passing this into a function, as a reference. so the function gets a &Commands parameters.

It then tries to do "for command in commands" to iterate through the contents of the Commands struct, but it can't.

originally this code had the IntoIterator trait implemented, but that doesn't work. Because (I'm reasonably sure) we don't have a Commands, we have a &Commands.

because defining an iterator (or IntoIterator) for Commands is different than defining one for &Commands

so... presumably I need to implement an iterator/IntoIterator for &Commands.

Not really sure how to do that, but I can hopefully figure it out

"in the trait associated type is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type"

that error makes sense. I just don't know how to do that

I didn't figure that out. I instead just explicitly called iter() on the reference which I defined to call iter() on the std::vec. So now i'm on to other, weirder problems

now I'm trying to figure out the following:

I have a vector of Commands (which is an enum). Some of them are Include commands. I need to go through the vec and replace the Include commands with the Commands from the item they're supposed to Include.

So I need to iterate through the vec and do something special when the command is an Include vs something else.

which sounds like a match but I need to run a block of procedural code in response to it being an Include, not just return a value

so I need something like:
for command in commands.iter(){
if type(command) == Include {
//do some stuff here
}
}

but I don't know the syntax for "if this enum is this type" or if this is a remotely reasonable pattern for rust code

and if-let.

I'm clone()ing everything these days. I'll make this more performant and efficient later

oh no, I'm borrowing a moved value!

I'm not really sure what that means or why it's a problem

okay my code for the Include nonsense is actually working now.

I have .clone() in 90 places and probably only need it in one or two

I shall try to fix this later

this code currently generates SVG files.
I don't really want to look up how to make it do that better, and I don't need that ability, so now I gotta figure out what to do next. I think I might implement a generate-to-text feature to debug/implement everything before I try generate-to-bytecode? I don't want to have to observe my results in a hex editor

I'm having to touch parsing code.

it hurts but I'm managing

OH GOD NO NOT THE BRAZILIAN FLAG

the complexity of the Brazilian flag is half the reason I'm learning Rust!

ok as I try to figure out how the parser works, I discover that I haven't properly implemented includes.

because right now this is resolving includes after parsing, but variables are resolved during parsing, but you should be able to include a flag for its variables.

so I'm going to have to somehow move the include handling into the parser, not after it. Nasty.

anyway right now I'm trying to figure out parsing variable declarations.
There's existing code that handles some basic versions of it, but the problem I'm currently facing is that there are multiple types of values in variable declarations. like:

$foo=42
$bar="hello"
$center=(320,240)
$background=RGB(255,0,255)

and I have nom-parsers that can handle parsing integers and strings and points and colors, but now I need to handle "it could be any of them"

and I've got an enumeration that can be any of them but I'm not sure how to tell nom about this. I can't do alt(integer, string, point, color) because each of those functions returns a different type

I solved it by writing wrapper functions that are basically identical. there is probably a way to make this more reasonable using generics or a single function with a match, but for now... it's inelegant but presumably at least functional

handling errors and types are the two main complexities of rust that I've run into so far

I'm currently trying to handle the type of errors, so I'm completely screwed

Follow

@foone Wouldn't it be faster to just rewrite it in python, c, or any other language really?

· · Web · 1 · 0 · 0

@DPA yeah. but this is also teaching me rust as a side-effect

Sign in to participate in the conversation
Awoo Space

Awoo.space is a Mastodon instance where members can rely on a team of moderators to help resolve conflict, and limits federation with other instances using a specific access list to minimize abuse.

While mature content is allowed here, we strongly believe in being able to choose to engage with content on your own terms, so please make sure to put mature and potentially sensitive content behind the CW feature with enough description that people know what it's about.

Before signing up, please read our community guidelines. While it's a very broad swath of topics it covers, please do your best! We believe that as long as you're putting forth genuine effort to limit harm you might cause – even if you haven't read the document – you'll be okay!