Style question: Do we prefer core:: or std::?

45 views
Skip to first unread message

Johnathan Van Why

unread,
Sep 4, 2021, 11:55:41 PM9/4/21
to Tock Embedded OS Development Discussion
In crates that are not #![no_std], should we refer to items in the core library via core:: or via std::? That is, do we refer to Cell as core::cell::Cell or std::cell::Cell?

I've been haphazardly using a mix in libtock-rs' codebase, which has a lot of crates (mostly testing crates) that use the standard library. This feels like one of those "we should pick a rule and stick with it" things that belongs in the Tock Style document.

An advantage of using core:: is consistency with our #![no_std] crates (which is a majority of the tock/tock repository). An advantage of using std:: is consistency with the greater Rust ecosystem, most of which uses the standard library.

Anyone have input on which name we should prefer? I personally prefer using core:: but I'm not strongly opinionated about it.

-Johnathan

Johnathan Van Why

unread,
Sep 4, 2021, 11:59:53 PM9/4/21
to Tock Embedded OS Development Discussion
Hmm, I sent that email then immediately thought of two more advantages of using std:: over core::
  1. It's one character shorter, reducing line wrapping. This is mostly alleviated by "use" statements, however.
  2. If you search for a core library component online, you are directed to the docs for the std:: version. Determining whether there is a core:: version takes an extra step.

Amit Levy

unread,
Sep 7, 2021, 11:11:45 AM9/7/21
to Johnathan Van Why, Tock Embedded OS Development Discussion

One advantage of using `core::` is that code _could_ be used from
`no_std` environments. For example, it's somewhat common in the Rust
ecosystem to have a `no_std` feature in a library that, when turned on,
elides some functionality but retains whatever can operate in `no_std`.

-Amit

"'Johnathan Van Why' via Tock Embedded OS Development Discussion"
<tock...@googlegroups.com> writes:

> In crates that are *not* #![no_std], should we refer to items in the core
> library via core:: or via std::? That is, do we refer to Cell as
> core::cell::Cell or std::cell::Cell?
>
> I've been haphazardly using a mix in libtock-rs' codebase, which has a lot
> of crates (mostly testing crates) that use the standard library. This feels
> like one of those "we should pick a rule and stick with it" things that
> belongs in the Tock Style
> <https://github.com/tock/tock/blob/master/doc/Style.md> document.
>
> An advantage of using core:: is consistency with our #![no_std] crates
> (which is a majority of the tock/tock repository). An advantage of using
> std:: is consistency with the greater Rust ecosystem, most of which uses
> the standard library.
>
> Anyone have input on which name we should prefer? I personally prefer using
> core:: but I'm not strongly opinionated about it.
>
> -Johnathan
>
> --
> You received this message because you are subscribed to the Google Groups "Tock Embedded OS Development Discussion" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to tock-dev+u...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/tock-dev/CAJqTQ1jVpDktHZhNyvyihX9koKnhetTQAO7sm_pHkq3pvMFVuQ%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages