@bobulous@fosstodon.org
@bobulous@fosstodon.org avatar

bobulous

@bobulous@fosstodon.org

Paid to write #Java, but much more interested in #Rust at the moment.

If for some reason you need an SHA-3 and #Keccak implementation in Java and don't want to use the JDK built-in or Bouncy Castle, then take a (cautious) look at my Codeberg repository.

If you fancy taking on the #FiftyStatesGame then see the /games section of my website.

If you need to create an #XSLT sheet which can generate multiple output pages in one go, you'll find that in the /coding section of my website.

This profile is from a federated server and may be incomplete. Browse more on the original instance.

hywan, to rust
@hywan@fosstodon.org avatar

libfuzzer has found a bug in my algorithm. Youhou. Fuzzing For The Win \o/.

bobulous,
@bobulous@fosstodon.org avatar

@hywan How many minutes/hours did it run for before it found it?

gregorni, to programming
@gregorni@fosstodon.org avatar

What does your development environment look like right now?

(IDE/Text Editor? Terminal Multiplexer? Package Manager? Shell? Programming Language? Containerization? Command Runner? Terminal Emulator?)

bobulous,
@bobulous@fosstodon.org avatar

@mo8it @gregorni What is a terminal multiplexer, and why is a terminal emulator needed?

I do development using Helix and rust_analyzer, running in one or more bash terminals on Fedora. What am I missing out on?

ancientjames, to random
@ancientjames@mastodon.social avatar

An increasing number of websites seem to be popping up boxes telling me I can't proceed until I disable my ad blocker, even though I don't use an ad blocker.

bobulous,
@bobulous@fosstodon.org avatar

@ancientjames I saw the same thing earlier. Are they all using some common JavaScript library which has developed a bug?

bobulous,
@bobulous@fosstodon.org avatar

@ancientjames @bobulous Maybe. I always have my browser auto-refuse website requests for my location and for showing notifications, so that could explain it.

If a website thinks I'm going to share my location or enable unwanted notifications, then that website will simply lose this visitor.

swsnr, to rust
@swsnr@mastodon.social avatar

Whenever I touch xjc and jaxb I wish that Rust had any decent XML libraries and codegen tools.

#rustlang #java #xml

bobulous,
@bobulous@fosstodon.org avatar

@swsnr I recently published a crate for reading XML:

https://docs.rs/spex/latest/spex/

There's no fancy unmarshalling; the entire document just gets read into an element tree. It does support namespaces, though, and I spent a lot of time creating traversal mechanisms (XmlPath and cursors) in the hope it makes it easy to grab the desired data out of the tree.

Probably not a JAXB substitute, but maybe useful in some scenarios.

#RustLang #XML

janriemer, to rust

The #Rust #parser combinator experience:

  1. Writing multiple parser combinator functions ✅
  2. The most "higher up" parser fails ❌
  3. Investigate reason 🔍
  4. Find out it's a whitespace char that has been parsed too eagerly 💡
  5. Fix eagerly parsed whitespace 🔧
  6. All tests pass ✅
  7. Rinse and repeat ➰

In all seriousness: 95% of errors I have are due to me parsing whitespace too eagerly (this is good!).

I'm using #chumsky, btw (beautifully designed parser combinator crate!).

#RustLang

bobulous,
@bobulous@fosstodon.org avatar

@janriemer I take it my recently released parser package ("sipp" on crates.io) is now considered old-fashioned technology because it just offers methods such as peek and require, and does not feature these new-fangled combinators that so many other parsing packages seem to offer?

bobulous, to rust
@bobulous@fosstodon.org avatar

Okay, finally published my #Rust powered parser and XML-specific parser packages to crates.io.

sipp: "Simple parser package"

spex: "Simple(ish) parser and extractor of XML"

I've not had time to push them to my Codeberg account yet, and there are problems with my initial attempt at README pages. But hopefully there's enough there to give an idea of what the packages offer.

Feedback welcome, especially about the "shape" of the public interface and how it "feels" in actual use.

#XML #RustLang

bobulous, to rust
@bobulous@fosstodon.org avatar

If I have a struct which implements methods from a trait, is there a way to avoid forcing the library user to import (use) both the struct and the trait name in their code? Keeps tripping me up and I wrote the library.

Simplified example:

struct MyStruct{
v: String
}

impl MyTrait for MyStruct {
fn my_method(&self) -> &str {&self.v}
}

When use blah::MyStruct is used, it's also necessary to use blah::MyTrait otherwise the method cannot be called. Way round this?

bobulous,
@bobulous@fosstodon.org avatar

@bryan Oh, interesting. I didn't know you could have the trait refer to a concrete implementation like that.

(In fact, I thought I had tried something like that somewhere else, and Rust told me off for using the same name twice in an ambiguous way.)

bobulous, to rust
@bobulous@fosstodon.org avatar

I was planning to have my parser and XML parser packages published to crates.io by now, but while writing example code I keep finding new features begging to be added, such as the ability to specify a default namespace before reaching for a chain of child elements.

But I'm pretty sure they say that scope creep always leads to the best outcome, right?

#Rust #RustLang #ScopeCreep #XML

bobulous, to rust
@bobulous@fosstodon.org avatar

Any sages know how to idiomatise this chunk of code which clippy is unhappy about?

for i in 0..read_limit {
let byte = self.content[self.next_index + i];
buf[i] = byte;
}

Clippy wants to get rid of the index i, but both of its hints lead to the code breaking.

I can't see a way to get rid of the index, seeing as it's needed in two different expressions across two different arrays/slices.

This is part of a Read::read(&mut [u8]) implementation, if you're curious.

bobulous,
@bobulous@fosstodon.org avatar

@ekuber Out of curiosity, how does this zip approach differ to the one suggested by @chmp which looks like this?

for (dst, src) in std::iter::zip(&mut buf, &self.content[self.next_index..]) {
*dst = *src;
}

bobulous, to rust
@bobulous@fosstodon.org avatar

I have, belatedly, realised that my parser needs to use dynamic dispatch, because the character encoding can only be determined at runtime. Which means all of my rigidly static generic structs need to have dynamic equivalents. But I want to keep the static generic versions too, so that (for example) a JSON parser can be built from them (JSON is always UTF-8 so no need for runtime determination).

The dynamic/static files are almost identical. Any way to avoid duplication?

bobulous,
@bobulous@fosstodon.org avatar

@divclassbutton Well, the battle with dynamic dispatch in is currently going so badly that I might end up leaving it as UTF-8. But I'll keep fighting with it a while longer, seeing as it would be useful to have the software detect supported encodings automatically.

bobulous,
@bobulous@fosstodon.org avatar

@janriemer @divclassbutton Maybe it's the way I've structured things, but because the encoding can't be determined until runtime, the compiler can't know which decoder to use. So, even though I'm already using a trait for the decoder, dynamic dispatch is needed to select the specific decoder at runtime.

I had almost no trouble with the borrow checker in eight weeks of working with static generic types, but after seven hours yesterday the dynamic code is wildly broken.

bobulous,
@bobulous@fosstodon.org avatar

@janriemer @divclassbutton I got the dynamic dispatch versions working eventually (tip: hunt down every dyn Trait and replace it with dyn Trait + 'a with extreme prejudice).

Then I decided you were right, and created static functions which simply wrap the messy bit in a non-generic type so that the client code doesn't need to worry about it. This won't allow the decoder to be swapped mid-stream, but I'm no longer confident that's really needed.

bobulous, to rust
@bobulous@fosstodon.org avatar

If anyone is wondering why is so popular with developers, it's simple: the helpfulness of the compiler.

My fancy XML iterator got me into a knot of lifetimes which wouldn't compile. In any other compiler I've ever known, this would mean a baffling error and then hours of hunting for answers online, maybe waiting days for someone wise to respond to a forum post.

Instead, the Rust compiler just says try rustc --explain E0700 which gives an explanation and the solution.

bobulous,
@bobulous@fosstodon.org avatar

@ekuber Do you have a direct link to the relevant issue reporting page, just in case?

bobulous, to rust
@bobulous@fosstodon.org avatar

Phew, had me worried for a minute. I'm writing a simple XML 1.0 parser in just for practice, and on feeding it a 4.4MB XML file it took 56.5s to read it. I've done nothing to optimise it yet, but even so that sounded dire.

Then I remembered to use "release" mode, and the time dropped to 3.9s. Whatever the compiler is doing behind the scenes, I'll take that 14x speed boost, thank you.

bobulous,
@bobulous@fosstodon.org avatar

@divclassbutton I intend to put it up on if I can get it to a suitably tested and elegant state. I'm fussing over the public interface, because that's tricky to change once you've unveiled it.

bobulous, to rust
@bobulous@fosstodon.org avatar

@imperio Any chance you can add a clippy lint warning when using the underscore in numeric literals with an odd format?

I just spent ten minutes hunting a bug before realising I'd written 0_32 instead of 0_u32.

Ideally clippy could spot that there are fewer than three digits after the underscore and warn that it looks suspicious. (I'm assuming people only use underscores to break big numbers into thousands, but it's possible I'm missing something.)

kubikpixel, (edited ) to rust
@kubikpixel@chaos.social avatar

deleted_by_author

  • Loading...
  • bobulous,
    @bobulous@fosstodon.org avatar

    @kubikpixel I'm using for programming and I love it. If you're going to give Helix a try then definitely follow the built-in tutorial first by typing (on the command line):

    hx --tutor

    And make sure to install the rust-analyzer tool so that Helix can highlight errors and warnings each time you save. Can be tricky to get the pieces to work together at first, but on re-reading the online instructions it becomes clear eventually.

    bobulous, to rust
    @bobulous@fosstodon.org avatar

    Is it possible in #RustLang to create a structure from a String so that it both holds that String and also holds a structure which references many slices into that String?

    Something like this shape:

    impl Doc {
    fn new(raw: String) {
    let doc = Doc {
    source: raw,
    parts: extract_parts(&source),
    };
    doc
    }
    }

    Right now, the compiler does not like the move/borrow if I refer to 'raw' twice, and it won't allow a reference to the struct field 'source'.

    Is this model possible?

    bobulous,
    @bobulous@fosstodon.org avatar

    @dpom That's a surprise. I had thought that if a struct owned a value then it was also safe for that struct to keep non-mut references into that value. But the article about Pin suggests that my understanding is wrong.

    bobulous, to rust
    @bobulous@fosstodon.org avatar

    Now I'm looking for some syntactic sugar in . At the moment I have this method signature:

    pub fn assert_ratio_tolerance<T: TryInto<Decimal>>(expected: T, actual: T, tolerance: T) where <T as TryInto<Decimal>>::Error: Debug

    and I'm hoping there's some way of creating a type alias, let's call it DebugDec, so that the method can be:

    pub fn assert_ratio_tolerance<T: DebugDec, U: DebugDec, V: DebugDec>(expected: T, actual: U, tolerance: V)

    Does Rust offer a way to create such an alias?

    bobulous,
    @bobulous@fosstodon.org avatar

    @brandon Are you using an unstable/nightly version of Rust?

    When I try your code I have to move the where clause before the equals sign to get the compiler to accept it, and even then the method declaration gives the error "type aliases cannot be used as traits".

    This page suggests that this might be possible using an unstable feature:

    https://doc.rust-lang.org/unstable-book/language-features/trait-alias.html

  • All
  • Subscribed
  • Moderated
  • Favorites
  • megavids
  • thenastyranch
  • rosin
  • GTA5RPClips
  • osvaldo12
  • love
  • Youngstown
  • slotface
  • khanakhh
  • everett
  • kavyap
  • mdbf
  • DreamBathrooms
  • ngwrru68w68
  • provamag3
  • magazineikmin
  • InstantRegret
  • normalnudes
  • tacticalgear
  • cubers
  • ethstaker
  • modclub
  • cisconetworking
  • Durango
  • anitta
  • Leos
  • tester
  • JUstTest
  • All magazines