Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign up(Modules) Tracking issue for `crate` as a visibility modifier #53120
Comments
Centril
added
B-RFC-approved
T-lang
C-tracking-issue
labels
Aug 6, 2018
Centril
added this to the Rust 2018 RC milestone
Aug 6, 2018
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Personally, I am very much in favor of |
Centril
referenced this issue
Aug 6, 2018
Closed
Tracking issue for RFC 2126: Clarify and streamline paths and visibility #44660
This comment has been minimized.
This comment has been minimized.
lilianmoraru
commented
Aug 6, 2018
•
|
I'm personally ok with writing use crate::menu::{Sound, Volume};
crate mod color;
...
/// A type for storing text and an associated color it should
/// be drawn as.
crate struct ColoredText {
crate color: types::Color,
crate text: &'static str,
}
|
This comment has been minimized.
This comment has been minimized.
|
Some of these examples are very C- |
This comment has been minimized.
This comment has been minimized.
|
The example due to @johnthagen does not read poorly to me. In fact, it reads naturally and I quite like the symmetry. It is beautiful in a way. If the readability of: crate struct ColoredText {
crate color: types::Color,
crate text: &'static str,
}becomes a problem; then an IDE/editor that understands the syntax of Rust can highlight the |
This comment has been minimized.
This comment has been minimized.
|
I'd personally would want to reuse |
This comment has been minimized.
This comment has been minimized.
|
It's been brought up before, but I think the root issues I see are:
// Here `crate` means the root of this crate.
use crate::menu::{Sound, Volume};
// Here, `crate` means: export crate::game::color
// The `crate` is referring to `color`, not the root.
crate mod color;
...
/// A type for storing text and an associated color it should
/// be drawn as.
// Same potential confusion as `crate mod color`
crate struct ColoredText {
crate color: types::Color,
crate text: &'static str,
}Compared to an example, using @matklad's use crate::menu::{Sound, Volume};
internal mod color;
...
/// A type for storing text and an associated color it should
/// be drawn as.
internal struct ColoredText {
internal color: types::Color,
internal text: &'static str,
}I'm not saying I also think the |
This comment has been minimized.
This comment has been minimized.
|
The slightly longer syntax of I find it to be just busy work currently in Rust 2015 if I ever mark a type from |
This comment has been minimized.
This comment has been minimized.
|
I also find @matklad's idea of re-purposing |
This comment has been minimized.
This comment has been minimized.
|
Repurposing What was less discussed and considered, I think, was repurposing I suspect this would be less disruptive, based on the assumption that there are fewer world-public items than crate-public items. It would also preserve the intuitive (though subtly incorrect) meaning of |
This comment has been minimized.
This comment has been minimized.
FWIW, though it only saves two characters, if we wanted to abbreviate |
This comment has been minimized.
This comment has been minimized.
|
@glaebhoerl The symmetry with It's short, (only 1 more character than The updated example would look like: use crate::menu::{Sound, Volume};
intern mod color;
...
/// A type for storing text and an associated color it should
/// be drawn as.
intern struct ColoredText {
intern color: types::Color,
intern text: &'static str,
} |
This comment has been minimized.
This comment has been minimized.
CasualX
commented
Aug 9, 2018
•
|
I've mentioned it before, but I'm not sure what the problem is with nouns used as adjectives? To recap: there are plenty of nouns that can be used as adjectives, eg. a house cat, a computer mouse, a computer desk, etc... A google search for english nouns used as adjectives seems to indicate there's nothing inherently wrong although not all nouns work as adjectives. Let's try it: crate mod hello; A crate module named hello, feels fine. crate use self::local::Foo; Ack, this one does not work, a crate use? You can read it as crate usable item named Foo. It does break the pattern. It can also be awkward when used in front of struct members and even more in combination with crate as the root of a path. While crate isn't perfect, I'm not convinced that 'being a noun' is a deciding factor. |
This comment has been minimized.
This comment has been minimized.
UtherII
commented
Aug 10, 2018
|
The problem is that it is very uncommon. There is no programming language I know that use nouns as type modifier. |
This comment has been minimized.
This comment has been minimized.
epage
commented
Aug 15, 2018
Personally, while I find features of different editors nice, I don't think we should design the language with the assumption of a sufficiently advanced editor. I felt like C# was designed this way and it was a major factor in my frustration with that language. |
This comment has been minimized.
This comment has been minimized.
|
@epage I think |
This comment has been minimized.
This comment has been minimized.
|
As an IDE person, I think such highlighting would add significant amount of noise for a very little amount of information, netting negative. IMO (this is highly personal, but informed by both using and implementing powerful IDEs) highlighting works best when it conveys semantic non-local information (does this usage refers to a variable that was declared with |
This comment has been minimized.
This comment has been minimized.
|
It seems to me that It has three letters (nice for alignment, easy to remember), it's not a noun, and - other than 'Document Object Model' - I don't think it has any particular ambiguity attached to it. pub struct MyStruct {
dom num: i32,
pub msg: String,
}Does anybody have thoughts on this? |
This comment has been minimized.
This comment has been minimized.
epage
commented
Aug 16, 2018
•
|
One angle on this that I've seen mentioned but couldn't find in the summary (thanks for doing that btw!) is how a shortcut fits in with the existing If For example, if we use
Considering this and my understanding of the goal (clarify public API from internal API), led me to recreate @vitiral's idea of
|
This comment has been minimized.
This comment has been minimized.
epage
commented
Aug 16, 2018
|
RE Impact on encapsulation One benefit of the existing While there will still be I suspect this isn't an issue because of the culture of small crates. But in considering this, it gives me another iteration on my above comment on
I previously brought up the concern of people transitioning from other languages. This better aligns with them.
imo this is the best of all worlds. So tear it apart and help me understand why not :) |
This comment has been minimized.
This comment has been minimized.
parasyte
commented
Aug 16, 2018
|
I still hate the |
This comment has been minimized.
This comment has been minimized.
|
@parasyte |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
Some thoughts from someone who changed camp: At first I was very opposed to I then tried it side-by-side in some of my projects and let it sink in. Frankly, after a few days I couldn't stand looking at Initially I feared there might be (visual) ambiguity; but to me the opposite happened: If I see I can see there might be still be residual "harder" (visual) ambiguity in some cases, but I wouldn't want to trade that back for what now feels like an massive quantitative readability win (as in: "source code lines that require less visual tokenization / effort vs. source code lines that became more ambiguous" ). From that angle Having said this, I don't know about parsing ambiguity. If I had to pick one, I'd much rather have a good story around " |
This comment has been minimized.
This comment has been minimized.
superseed
commented
Aug 21, 2018
|
@rpjohnst Is it really what it always meant? Wasn't it the chain of "visible from |
This comment has been minimized.
This comment has been minimized.
|
No, that's not the whole story, and @seanmonstar's clarification hints at the rest. The biggest exception is reexports- you can And going in the other direction, So an item's own visibility is not directly about its visibility to |
This comment has been minimized.
This comment has been minimized.
superseed
commented
Aug 21, 2018
|
Oooh okay, thanks for the clarification! I had a much more naive model in mind. It makes more sense regarding previous comments about "the current meaning of pub". |
Centril
added
I-nominated
and removed
I-nominated
labels
Aug 23, 2018
This comment has been minimized.
This comment has been minimized.
|
We discussed briefly today in @rust-lang/lang meeting:
|
This comment has been minimized.
This comment has been minimized.
|
Answer: we parse it as a path (playground). This seems.. probably ok to me, because I think that |
This comment has been minimized.
This comment has been minimized.
epage
commented
Aug 23, 2018
@nikomatsakis are there meeting notes or a summary for us to catch up on? Within this thread, I've not seen discussed at least one of my concerns[0] nor much discussion on the counter proposals. Maybe [0] and some of the others were discussed in the various internals threads but that is a lot to dig through. [0] creating a parallel visibility syntax pushing |
This comment has been minimized.
This comment has been minimized.
No sorry; We did not discuss it for very long (a few minutes at most) and did not write down any meeting notes about it. @eddyb briefly alluded to |
This comment has been minimized.
This comment has been minimized.
|
I think I said EDIT: if our struct Foo(my FooImpl); |
This comment has been minimized.
This comment has been minimized.
Perl: making jokes a reality. |
This comment has been minimized.
This comment has been minimized.
|
The awkward situation we're in is that we want to have three privacy levels -- "completely public", "completely private", and "somewhere in between" (i.e., crate-level) -- and due to backwards compatibility constraints we're stuck with the first of these necessarily being And the Meanwhile So that's basically the shape of the predicament. 1 (Someone above described an interaction which went, "they asked what |
This comment has been minimized.
This comment has been minimized.
|
FWIW, I'd be totally okay with |
This comment has been minimized.
This comment has been minimized.
|
How do people feel about |
This comment has been minimized.
This comment has been minimized.
|
IMO Regarding extern fn foo() {
println!("Just called a Rust function from Rust!");
}
#[no_mangle]
extern "C" fn foo_from_c() {
println!("Just called a Rust function from C!");
}I haven't seen that mentioned in the threads I've read so apologies if this has been discussed before! |
This comment has been minimized.
This comment has been minimized.
Yes- sometimes you only want to use |
This comment has been minimized.
This comment has been minimized.
|
Here's a suggestion that came up long time ago - maybe we can give it another chance now that some aspects of the new module system have been crystallized? // Public to the world.
pub struct Foo;
// Private to the crate.
priv struct Foo;
// Basically not visible at all (only inside the module).
struct Foo;I believe this makes sense if one thinks of:
Some people had a knee-jerk reaction to
|
This comment has been minimized.
This comment has been minimized.
stevensonmt
commented
Aug 24, 2018
|
@stjepang I would argue that in most other circumstances "private" is going to have a more restrictive connotation than an unmodified state. The private-default-public spectrum in a general sense is analogous to protected-available-advertised. A private club is more exclusive than a club. As an inexperienced language learner, I would also suggest that an additional keyword is less of a cognitive burden than a single keyword with multiple context-dependent meanings. See Costello, L and Abbot, B "Who's on first", 1938. |
This comment has been minimized.
This comment has been minimized.
|
I feel that I honestly feel like people would learn what
I personally don't see those as showstoppers, but they're definitely legitimate concerns here. |
This comment has been minimized.
This comment has been minimized.
|
There's a parallel of |
This comment has been minimized.
This comment has been minimized.
|
It occurs to me that the C++ concept of |
aturon
removed this from the Rust 2018 RC milestone
Sep 5, 2018
This comment has been minimized.
This comment has been minimized.
gdouezangrard
commented
Sep 9, 2018
•
|
Ultimately, the issues are:
After 5 minutes of really deep thinking, I came up with the following... :P Special Syntax for the Visibility Modifiers(using @pub use crate::Foo;
@crate struct Bar;I personally find that quite ugly and I would not want to type either Distinct Visibility Modifiers KeywordsSince there's already the bare crate struct Foo;
crate fn path() -> PathBuf { ... }But as I said, that doesn't work well with the
looks like With great inspiration from the declarative macros syntax, instead of finding some kind of unified syntax for visibility modifiers, I would rather have the following: use std::io;
use std::path::Path;
use log::info;
use $crate::utils;
crate fn hello() -> io::Result<()> {
utils::rm_rf(Path::new("/"))?;
info!("Goodbye, World!");
}( Convoluted example: crate struct Foo(crate crate::Bar);becomes: crate struct Foo(crate $crate::Bar); |
This comment has been minimized.
This comment has been minimized.
|
It appears there's a duplicate tracking issue: #45388. |
Centril commentedAug 6, 2018
•
edited
This is a sub-tracking issue for the RFC "Clarify and streamline paths and visibility" (rust-lang/rfcs#2126)
dealing with the question of
crateas a visibility modifier.Unresolved questions:
struct Foo(crate ::bar)?