Baseless Types?

In the swagger-codegen for the rust client, there is an odd reference that I cannot find elsewhere. It looks like a baseless type reference, but I am not sure.


What is the ::apis::... ? I thought all of these references needed to be based on some object or type?
What is this a trait of? ???::apis::...

a prefix :: means "look in the dependencies of this crate", so it will look for a dependency named apis

(I'm not sure if this is exactly what it means, but it's covers most cases)

Why put two colons before apis though? Typically, the crate is supposed to come before the ::, no? Does it just mean, 'look in this local file for this type'?

If you put crate out from, crate::apis then you are saying look for a top-level module named apis, not a dependency named apis. It's an old syntax, now you can just say apis:: without the leading ::

So, I can delete those two colons and have it behave exactly the same?

It should. If you are on the 2018 edition, and you don't have a sub-module named apis

Splendid, thanks! I'll include that in the pr.

I would leave it in, it prevents conflicts like

// I have a dependency named apis as well
mod apis;

// which does this refer to? the module,
// but we wanted it to refer to the dependency
use apis::???;

// this is the correct way to refer to the dependency
use ::apis::???;

It looks like it's trying to prevent this sort of ambiguity, or is trying to be backwards compatible.

1 Like

Okay, I will leave it then, thanks.

It's kinda like the module version of Universal Function Call Syntax. Like how you might write <SomeType as std::io::Write>::write(&mut some_writer) when both std::io::Write and std::fmt::Write are in scope (they both have a write() method).

You'll often see it used it in macros or generated code, because you don't necessarily know what the caller will have in scope at the time and want to avoid ambiguities.