this post was submitted on 23 Jan 2024
358 points (96.6% liked)

Fediverse

28362 readers
998 users here now

A community to talk about the Fediverse and all it's related services using ActivityPub (Mastodon, Lemmy, KBin, etc).

If you wanted to get help with moderating your own community then head over to !moderators@lemmy.world!

Rules

Learn more at these websites: Join The Fediverse Wiki, Fediverse.info, Wikipedia Page, The Federation Info (Stats), FediDB (Stats), Sub Rehab (Reddit Migration), Search Lemmy

founded 1 year ago
MODERATORS
 

Seems like an interesting effort. A developer is building an alternative Java-based backend to Lemmy's Rust-based one, with the goal of building in a handful of different features. The dev is looking at using this compatibility to migrate their instance over to the new platform, while allowing the community to use their apps of choice.

you are viewing a single comment's thread
view the rest of the comments
[–] Rooki@lemmy.world -1 points 9 months ago (12 children)

That i dont understand? How can it be a result that i need to handle? If its not correct than java will throw an error. ( As expected, shit in shit out )

[–] kattenluik@feddit.nl 4 points 9 months ago* (last edited 9 months ago) (11 children)

It's a great and probably the best error system I've seen, instead of just throwing errors and having bulky try catch statements and such there's just a result type.

Say you have a function that returns a boolean in which something could error, the function would return a Result<bool, Error> and that's it. Calling the function you can choose to do anything you want with that possible Error, including ignoring it or logging or anything you could want.

It's extremely simple.

[–] uranibaba@lemmy.world 1 points 9 months ago (10 children)

If I except a boolean, there is an error and get a Result, is Result an object? How do I know if I get a bool or error?

[–] kattenluik@feddit.nl 1 points 9 months ago* (last edited 9 months ago) (1 children)

Here's some examples written on my phone:

match result {
    Ok(bool_name) => whatever,
    Err(error_type) => whatever,
}

if let Ok(bool_name) = result {
    whatever
}

if result.is_ok() {
    whatever
}

let whatever = result.unwrap_or_default();
let whatever = result?;

And there's many other awesome ways to use a Result including turning it into an Option or unwrapping it unsafely. I recommend you just search "Rust book" on your search engine and browse it. Here's the docs to the Result enum.

[–] uranibaba@lemmy.world 1 points 9 months ago (1 children)

Ah, so it is like a wrapper enum, ok contains the data type you want and err the error object?

[–] kattenluik@feddit.nl 1 points 9 months ago

Exactly! The other wrapper enum I named (Option) is the same kind of concept but with Some(value) and None.

load more comments (8 replies)
load more comments (8 replies)
load more comments (8 replies)