this post was submitted on 14 Dec 2024
9 points (100.0% liked)

Rust Programming

8228 readers
20 users here now

founded 5 years ago
MODERATORS
 

I am trying to understand the std::process::Termination trait.

As I'm not really used to read libraries, I took this as a challenge to try understanding a bit more about how to read them as well.

I think trying to build a library would give me better understanding, but for now...

Termination is quite easy, from the trait page I can see that this trait has single method: report, which returns an ExitCode.

pub trait Termination {
    fn report(self) -> ExitCode;
}

But when I try to dig in further and i read the page related to ExitCode, it confuses me a bit.

ExitCode is a struct, therefore it behaves like a type with many fields which define the types contained in the struct.

I cannot really understand what's the point of this type.. I don't see any fields defined in the struct and this part confuses me a lot:

The standard library provides the canonical SUCCESS and FAILURE exit codes as well as From for ExitCode for constructing other arbitrary exit codes.

I even thought this meant it was an enum which had the SUCCESS, FAILURE etc as variants, but this does not seem the case.

Can you help me to understand how this specific structs work, what exactly does it do and how I should read library pages like this one?

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 1 points 2 days ago

In addition to the other comment about the exit code, you might be interested in the exitcode crate, which offers up a BSD convention for those exit codes.

They are, essentially, just numbers on unixes and don't really have as much standardization as e.g. HTTP codes afaik. Various programs may have their own local conventions as to what an exit code means.